Home Technical Talk

Maya: Good way to randomize between 3 integers?

polycounter lvl 18
Offline / Send Message
kodde polycounter lvl 18
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!

Replies

  • CrazyButcher
    Offline / Send Message
    CrazyButcher polycounter lvl 18
    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
    Offline / Send Message
    Surfa polycounter lvl 12
    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
    Offline / Send Message
    kodde polycounter lvl 18
    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.
Sign In or Register to comment.