Page 1 of 1

random

PostPosted: Fri Mar 25, 2005 6:19 am
by yep
how random works in GE?

PostPosted: Fri Mar 25, 2005 6:53 am
by Just4Fun
yep:
Your best bet is to search the forum using "random" or "rand" as your search term. There are a number of threads that discuss randomizing. The code depends somewhat on what you are trying to accomplish in your program.

If you are pretty comfortable with the c scripting, you might want to take a look in the demo section and download "Fortune Cookie Sooth" The program uses the rand() function to generate different fortunes. HTHs

PostPosted: Fri Mar 25, 2005 7:16 am
by yep
Just4Fun wrote:yep:
Your best bet is to search the forum using "random" or "rand" as your search term. There are a number of threads that discuss randomizing. The code depends somewhat on what you are trying to accomplish in your program.

If you are pretty comfortable with the c scripting, you might want to take a look in the demo section and download "Fortune Cookie Sooth" The program uses the rand() function to generate different fortunes. HTHs


let me test here...but is the rand(1) a number being generate from 0 to 1?

PostPosted: Sat Mar 26, 2005 2:28 am
by Just4Fun
As stated in the documentation:
C syntax for rand:
double rand(double a) //returns a value between 0 and a

In your case rand(1), would return a double value between 0 and 1.

You can see rand(1) by creating an Actor: myActor
Now, in the MyActor panel use the Add Event --> Create Actor
--> Add Action -->Create Script
Use the following script:
myActor.textNumber=rand(1);

When you run the program, you will see something like: 0.445357.
Each time your run the program, the number will change.

PostPosted: Sat Mar 26, 2005 5:41 am
by yep
ty man! for both topicos...

PostPosted: Sat Mar 26, 2005 2:15 pm
by willg101
Thanks!
This just what I was about to ask!