# random value between 0 to 1 from particle ID

 10 October 2009 Eraq Frequenter Erik Nielsen Copenhagen, DK random value between 0 to 1 from particle ID Hey Folks. Here is a noob question :-) How can I get an random value that is between 0 and 1 based on particle ID? Cheers Erik share quote
 10 October 2009 Aikiman Expert   portfolio Jeremy Raven Wellington, New Zealand x = b/a, where b = particleId and a = total number of particles. So if you have 700 particles and you want to find the normalised value for the 333rd particle, then... 333/700 = 0.48 Im no mathematician but I know that one . Does that help? __________________ Vimeo share quote
 10 October 2009 AndersEgleus Lord of the posts   portfolio Anders Egleus FX TD/R&D Ghost VFX, Cph Malmö, Sweden Jeremy: that's not very random is it? I'm guessing by random you mean that if you input two ids next to each other (e.g. 7 and 8), the random numbers should look completely unrelated (e.g. 0.684312 and 0.154789 respectively), shouldn't look like a sequence if you go through a lot of successive ids etc. Well, maya unfortunately doesn't really have a good function for that - you can ``````seed (particleId) float \$myRandomNumber = rand(0.0, 1.0);`````` but that will look very sequential if you study the numbers from successive ids. If you're emitting over a big area/volume you probably won't notice, but if you have an omni emitter the looping may get painfully obvious. ``````seed (particleId) float \$myRandomNumber; for (\$i = 0; \$i < 20; \$i++) \$myRandomNumber = rand(0.0, 1.0);`````` probably works better since a good random number in mel requires the sequence to run a few times, but it's of course more expensive. Or I may have misunderstood your question in which case Jeremy is right share quote
 10 October 2009 Eraq Frequenter Erik Nielsen Copenhagen, DK Hey Thanks for your answers guys. Much appriciated. My problem is that I would like to give my particles a random contribution to their velocity. So I thought that a random value based on the particles ID would do the trick. But unlike Houdini wich random functions return a value between 0 and 1, Maya´s random function lacks just that. Ill try the method you mentions. Thanks Erik share quote
 10 October 2009 stooch Lord of the posts   portfolio Dimitri Loginowski VFX Artist + Designer Handsome, LLC Beverly Hills, USA Originally Posted by Eraq: Hey Thanks for your answers guys. Much appriciated. My problem is that I would like to give my particles a random contribution to their velocity. So I thought that a random value based on the particles ID would do the trick. But unlike Houdini wich random functions return a value between 0 and 1, Maya´s random function lacks just that. Ill try the method you mentions. Thanks Erik you can do that. rand() by default will return a value between 0-1 i think what the guy above you was talking about SEED. you can set the seed by making it equal the particle id. Im writing this off the top of my head so dont remember the function, just do a search for controlling seed in the function library. __________________ From Russia, with love @ stooch.tv Last edited by stooch : 10 October 2009 at 10:19 PM. share quote
 10 October 2009 Aikiman Expert   portfolio Jeremy Raven Wellington, New Zealand Quote: Jeremy: that's not very random is it? clearly I didnt understand what he was driving at it appears ok in that case you dont necessarily need to use your Id but instead create a custom per particle attribute and in creation make give it a random value rand(1). Then use that as a multiplier on your velocity per particle. You could make it a vector thereby increasing the randomisation because you could affect each axis with a different value, or make it a float and multiply it over the entire vector. I would only use Id if you actually want specific particles to be affected, but in your case I dont think you do. __________________ Vimeo Last edited by Aikiman : 10 October 2009 at 10:34 PM. share quote
 10 October 2009 AndersEgleus Lord of the posts   portfolio Anders Egleus FX TD/R&D Ghost VFX, Cph Malmö, Sweden Yeah, Jeremy's technique is much better in practice than what I suggested in my previous post. To assure that the random values are the same every time you play back (as long as everything else stays the same) you can write ``````if (particleId == 0) seed (3212) // (or whatever arbitary seed value you choose - i just punched the numeric keypad)`````` In the creation expression. This, however, assumes that there is a particle with particleId = 0 - not the case e.g. if you use surface emission with texture rate. But if that is the case it works because the particle with id = 0 is the first to be evaluated, so its creation expression is the first thing that's gonna be evaluated in the scene when you playback - thus everytime after that where you use rand (), that seed is gonna be used. share quote
 10 October 2009 Aikiman Expert   portfolio Jeremy Raven Wellington, New Zealand Originally Posted by AndersEgleus: This, however, assumes that there is a particle with particleId = 0 - not the case e.g. if you use surface emission with texture rate. Is that a fact? I did not know that, do you have any idea why this is so? __________________ Vimeo share quote
 10 October 2009 Eraq Frequenter Erik Nielsen Copenhagen, DK Hello Folks. Thanks for your responses. It helped a lot Erik share quote
 10 October 2009 AndersEgleus Lord of the posts   portfolio Anders Egleus FX TD/R&D Ghost VFX, Cph Malmö, Sweden Quote: Is that a fact? I did not know that, do you have any idea why this is so? No, a quick test indicates that I was wrong - it seems that no matter how small a part of your mesh is emitted from with texture rate emission, the first particle always has id 0 anyway, which is good news to me - makes the seeding a lot safer. I distinctly remember coming across the problem of disappearing ids with texture emission, as if the emitter bumped the id before dismissing a particle, but that was a long time ago so it might have been fixed in the newer maya versions. Thanks for making me check, it's nice to find a maya particle feature for once which is actually MORE stable than you expected . share quote
 10 October 2009 Aikiman Expert   portfolio Jeremy Raven Wellington, New Zealand Originally Posted by AndersEgleus: No, a quick test indicates that I was wrong - it seems that no matter how small a part of your mesh is emitted from with texture rate emission, the first particle always has id 0 anyway, which is good news to me - makes the seeding a lot safer. I distinctly remember coming across the problem of disappearing ids with texture emission, as if the emitter bumped the id before dismissing a particle, but that was a long time ago so it might have been fixed in the newer maya versions. Thanks for making me check, it's nice to find a maya particle feature for once which is actually MORE stable than you expected . mmm maybe the first object in the particle array was used for something else when emitting from texture, dont ask me what, or maybe it was just a bug. Glad to be of some help anyway __________________ Vimeo share quote
 10 October 2009 CGTalk Moderation Expert Thread automatically closed This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum. __________________ CGTalk Policy/Legalities Note that as CGTalk Members, you agree to the terms and conditions of using this website. share quote

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts vB code is On Smilies are On [IMG] code is On HTML code is Off CGSociety Society of Digital Artists www.cgsociety.org Powered by vBulletinCopyright ©2000 - 2006, Jelsoft Enterprises Ltd.