# 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 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 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;```

##### 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

## Create an account

Register a new account