Search - User list
Full Version: rand() function
Root » Houdini Learning Materials » rand() function
Tatyana Kassinova
Hello.
Can anybody explain me how rand() function exactly work? I read the documentation, but it don't gave me answer on my question.

I know that it's work in range from 0 to 1. Why not from -100 and 100 and other (I know about fit() function). I try understand the logic of rand() function. I confused about using variable, such as $F and $ID for seed. When I use $F as seed all range of frame fits to 0 to 1? 0 will be 1 frame and 1 will be 240 frame? Right? Or not?

Thank.
bollili
No, I don't think you're right, if I understand your question correctly.

Yes, rand() gives results between 0 an 1. It's just designed like that. A good idea, imho. Because you can just multiply or use fit-functions to have the desired value range. Just think of 0 to 1 as *percent*.

Rand() is a pseudo random function. If you feed it with the same seed value, it will give you the same result. This behaviour is essential, because the results don't vary if you run the animation again.

So, to achieve a result, that *feels* like it's random, you have to vary the seed value over time ($F is the frame integer, so it's unique for each frame - better use $FF since it's float), over the particle id ($ID) or something else. E.g. the object's z coordinate or any other attribute you can imagine.
Tatyana Kassinova
I started to understand… seems….

Thank you, Bollili.
fsimerey
fit01() function is very useful with rand().
You only need to specify your range.

If you want a range between -1 and 1 :
fit01(rand($FF, -1, 1)

between -5 and 127:
fit01(rand($FF, -5, 127)
Sadjad Rabiee
Also we usually to define seed value for rand function to take different random result :
example :
rand($PT + “seedValue”)

And you should be careful about using $PT and $ID for particles.
$ID is unique number for each particles forever.
But $PT is a point number for currently particles , If one particle die after certain time , it lend it's $PT number to new generated particle and this is not unique !!!

I made a very simple example about using rand function for you :wink:
Tatyana Kassinova
Thank you guys!
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB