ChazS Posted January 23, 2019 Share Posted January 23, 2019 I'm trying to understand how to properly write/understand rand() functions. In particular, when emitting a particle from a random position along the x-axis, within a specific range (e.g. 2.5 to 2.9 units). My best guess is to write the following expression for the x-axis of the POP location node: fit01(rand($F), 2.5, 2.9)) but the particle launches from the same point every time since the starting frame is always the same. However, I don't know any other way to seed the start point to give it a sense of randomness (real, pseudo, or otherwise). Obviously I'm misunderstanding something here so if anyone can point me toward my mistake... Many thanks in advance. Quote Link to comment Share on other sites More sharing options...
anim Posted January 23, 2019 Share Posted January 23, 2019 1 hour ago, ChazS said: ...x-axis of the POP location node: fit01(rand($F), 2.5, 2.9)) but the particle launches from the same point every time since the starting frame is always the same... you have mismatched parentheses, try this: fit01(rand($F), 2.5, 2.9) Quote Link to comment Share on other sites More sharing options...
ChazS Posted January 23, 2019 Author Share Posted January 23, 2019 Oops, my bad, but the typo was only here and not in the actual file. X-pos updates every frame (which makes sense given how this is written) but there isn't any randomization on the first frame, so it always starts in the same spot. How do I get the first frame to randomize? Quote Link to comment Share on other sites More sharing options...
merlino Posted January 23, 2019 Share Posted January 23, 2019 (edited) Well, the particle "launches from the same point every time since the starting frame is always the same" it's true, as rand is a pseudo-random function. If you need some variation you'll need to create some sort of seed, so you can put $F+n (with n as any number, like $F+354 or $F+387.24) or $F*n. You can also add a parameter and use it as seed, so you just change that value with a slider and not hard coding it. EDIT: it should be something like fit01(rand($F+354),2.3,2.9) and you can change 354 (n) as you want Edited January 23, 2019 by merlino Adding the expression example Quote Link to comment Share on other sites More sharing options...
j00ey Posted January 23, 2019 Share Posted January 23, 2019 (edited) It's not usually desirable to have a random number that changes every time it's evaluated, in general you want the same result every time you feed the function the same seed [in your case $F]. What I usually do is as merlino suggests, but I usually add 'seed', 'min' & 'max' parameters to the node [or a control null somewhere] and reference them, eg : fit01(rand($F + ch("seed")), ch("min"), ch("max")) If you do really want a different result every time you could write a python expression in the seed field to, for example, return the time. Edited January 23, 2019 by j00ey Quote Link to comment Share on other sites More sharing options...
ChazS Posted January 23, 2019 Author Share Posted January 23, 2019 Thank you anim, merlino and j00ey. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.