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.
rand() function
18104 5 4-
- Tatyana Kassinova
- Member
- 13 posts
- Joined: Dec. 2013
- Offline
-
- bollili
- Member
- 214 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.
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
- Member
- 13 posts
- Joined: Dec. 2013
- Offline
-
- fsimerey
- Member
- 279 posts
- Joined: Dec. 2009
- Offline
-
- Sadjad Rabiee
- 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:
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
- Member
- 13 posts
- Joined: Dec. 2013
- Offline
-
- Quick Links