rand command

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

Thread Tools Search this Thread Display Modes
  11 November 2012
rand command

Hi there,

I've written a script that generates images for scene files, however I have this line:

Quote: float $rando, $rando= rand(.15, .85);
setAttr ($plane_mat + ".color") -type double3 $rando $rando $rando;

Every time the script is called it launches a new instance of maya.exe (without UI) and $rando is generated....but it's always the same colour.

Obviously if you use the code in one instance of Maya, it works okay. Anyone know what to do ? How to make it random everytime maya.exe opens?
  11 November 2012
computers can't actually generate real random numbers, they can only choose pseudo-random numbers from a stream, or list. It seems that becasue your script is spawning a new instance of Maya in the same way each time, the random stream it's using is in the same state each time.
Open up the MEL docs for the rand command and read the info at the top which explains how streams work, how you can set them and other related commands like seed.
It may be that in your script you have to set the seed or stream to something "random" like the current time or date, etc..

incidentally, you know you'll only ever get grey colours using that code right? as you use the same value for R, G and B. I'm assuming this is intentional, but I thought it best to mention it anyway just in case. Additionally, you can create random vectors too which is good for random colours.
  11 November 2012
Thanks Nathan for taking the time to reply to simple problems like this....I thought this might have been the case, but I didn't know how to go about it, now I do!

Yes, the intention is to get random grey backgrounds in my modelBank browser (like this:

Makes it easier for me and looks better for some reason.
  11 November 2012
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.
Thread Closed share thread

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
Society of Digital Artists

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump

All times are GMT. The time now is 01:41 AM.

Powered by vBulletin
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.