PDA

View Full Version : Maya: Good way to randomize between 3 integers?


kodde
08-30-2011, 09:44 AM
Hey all,

Sorry if this has been covered, could not find it.

I'm using particles and the Instancer feature to scatter geometry around. I have three different source meshes and I created my own UserScalarPP value that use use as my index value. This value is used to choose which of these three meshes will be used for that specific particle.

0 = mesh1
1 = mesh2
2 = mesh3

Here's my question. How do I get a random feature which should give me an even distribution of probabilities between these three integers?

particleShape1.userScalar1PP = rand(0,2); <- This just gives me a float between 0.00-2.00, which is convereted? to an integer. It does work, but is far from even when it comes to probability.

I've tried the usage of +0.5 together with the Floor() command, but that doesn't give an even probability either right?

Thanks!

CrazyButcher
08-30-2011, 09:59 AM
you would want [0,3[, so you get even intervals 0-1, 1-2, 2-3
could do 0,2.999999 or to make sure you never get 3 ;)

is there no integer rand? then you could just do rand() % 3;

Surfa
08-30-2011, 10:51 AM
Yeah you are going to want to use rand(0,3) and if the rounding doesn't work you could always implement that yourself with some simple if statements.

kodde
08-30-2011, 09:48 PM
Thanks guys,

So floor(rand(0,3) would work right? Floor will round downwards to the nearest integer right?

Or even floor(rand(0,2.99999).

CrazyButcher> I tried searching for an integer rand earlier, but couldn't find one.

EDIT:
Tried it out this morning and seemed to work good at glance. I did not do any exact measuring though.