Jump to content
SteveNi

Ranged random function

Recommended Posts

Hi

I want to randomly select two points from a geo input in a VEX wrangle, so far I have this:

int _selectedPts[];
 
_selectedPts[0] = rand(@numpt); 
_selectedPts[1] = rand(@numpt);

setattrib(geoself(),"point", "Cd", _selectedPts[0], 0, {1,0,0}, "set");
setattrib(geoself(),"point", "Cd", _selectedPts[1], 0, {1,0,0}, "set");

I searched on the VEX docs but every random function I found could only return float numbers, but I need integer numbers.

How can I solve this?

Share this post


Link to post
Share on other sites

What about something like this..?

int _selectedPts[];
 
_selectedPts[0] = int(fit01(rand(@ptnum),0,@numpt)); 
_selectedPts[1] = int(fit01(rand(@ptnum+311),0,@numpt));

setattrib(geoself(),"point", "Cd", _selectedPts[0], 0, {1,0,0}, "set");
setattrib(geoself(),"point", "Cd", _selectedPts[1], 0, {1,0,0}, "set");

rand() returns a float between 0 and 1. The fit01() remaps that into a range between 0 and number of points. Use the current point number as a random seed.

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

×