Maya> other>Random Numbers Part One

Random Numbers Part One

Share |
h4 class = head align =center>Random Numbers Part One

A lot of times in Mel you'll want to create a random number. This tutorial show you the simplest way of creating a random number from 2 numbers range. First let's set up a simple procedure (if you don't understand working with variables and procedures scripts, see my tutorial "Procedures Part One and Two. Link;).


The simplest of all randomization scripts that you can use is "rand(from here, to here)". Type this into your script editor and hit enter o your number pad to execute it.

This will return a random number between 1 and 5. Now, back to our code. Add the following code; The variable num equals how many spheres will be created.

First, let's make num equal a random number from 1 to 10 with this line of code;

Now execute the code. Type random in the command line. Now do it again. Each time it create a different number of spheres. Take it one step further by allowing you to define how much randomization you can have. Let's say you'll only want to create spheres from 3 to 5. First we're going to have to add 2 new variables. Then have the random options equal them. Here's what the code would look like finished;

Now type in random 2 5. Now it'll create a random amount of spheres from 2 to 5.

Home Tutorials About the Author Site Map
User Agreement Privacy Policy ©2015