Jump to content
art3mis

Randomly choose between 4 options

Recommended Posts

What's the most efficient way in vex to choose between 4 different options? Right now I am simply using rand and a series of if statements to check the resulting value. Is there a better way?

Share this post


Link to post
Share on other sites

you can use sample_discrete() function to get the index and then get your value from an array of values, it can be uniform or weighted

or you can use ramp parameter with constant interpolation and look up the value using random 0-1 number

Share this post


Link to post
Share on other sites
Posted (edited)

i like this way
like you said rand, but with floor function

 

@choose=floor((rand(@ptnum)*4)+1);

Edited by golubevcg

Share this post


Link to post
Share on other sites

Thanks. Is there any way in vex to incorporate method calls directly with your solution, or would I still need to use an if, else once I get my @choose value?

Share this post


Link to post
Share on other sites

just pick the value from an array based on that index

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×