Jump to content
philpappas

Choose Randomly with even distribution

Recommended Posts

I have this expression to choose from a set of numbers randomly. (1,2,3,4,5,6....49,50)

floor(rand($PT*ch("seed"))*detail("../node/","total",0))

My problem is that out of 50 numbers that i have only 23 make it after the expression. How can i make sure every number gets picked?

Share this post


Link to post
Share on other sites

I don't think I would use a floor for that.

Maybe try...

int rnd_index = int(fit01(rand(@ptnum+ch("seed")),1,50));

The nature of random numbers is that you might not get all 50 variation, while processing 50 points.

To achieve that consider randomizing a list/array and using the point number as an index into that list.
https://www.sidefx.com/forum/topic/52579/?page=1#post-236406

Share this post


Link to post
Share on other sites

i guess int is rounding to nearest integer, while floor will allways go down.

//floor
i@rnd_value = int(floor(rand((@ptnum+1)*(chi("seed")+1))*chi("range")))+1;

//rint
i@rnd_value = int(rint(rand((@ptnum+1)*(chi("seed")+1))*chi("range")))+1;

random_distribution_02.gif.f717682085241a705ec19e6e2289e850.gif

Share this post


Link to post
Share on other sites

thanks a lot for the pointers! i will try both when i find time and get back to you

22 hours ago, Atom said:

To achieve that consider randomizing a list/array and using the point number as an index into that list.

that is actually a very good idea

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

×