rand() function

   17043   5   4
User Avatar
Member
13 posts
Joined: Dec. 2013
Offline
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.
User Avatar
Member
205 posts
Joined: Dec. 2009
Offline
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.
User Avatar
Member
13 posts
Joined: Dec. 2013
Offline
I started to understand… seems….

Thank you, Bollili.
User Avatar
Member
279 posts
Joined: Dec. 2009
Offline
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)
User Avatar
Member
1391 posts
Joined: Dec. 2010
Offline
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:

Attachments:
JKRand.hip (144.4 KB)

https://www.youtube.com/c/sadjadrabiee [www.youtube.com]
Rabiee.Sadjad@Gmail.Com
User Avatar
Member
13 posts
Joined: Dec. 2013
Offline
Thank you guys!
  • Quick Links