Jump to content

Ranged random function


SteveNi

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?

Link to comment
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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...