Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Generating a random number/delay in seconds?

a lost user
Join date: ?
Posts: ?
08-13-2005 20:15
ll---something for both of these things? Thanks =D
a lost user
Join date: ?
Posts: ?
08-13-2005 20:55
From: Kujila Maltz
ll---something for both of these things? Thanks =D


float llFrand(float mag);

This is the main random number generator for scripting. As the function declaration suggests, it returns a float value based on the float value (mag) given to it. In practical terms this mean that if you want to get a random number between 0 and 5, you would call:
float number = llFrand(5);

If you need to get a number between 1 and 5, use this:
float number = llFrand(5) + 1;

If you actually want an integer (whole number) value instead, you will need to either typecast the return value or use a function that returns an integer based on a float or calculation such as:
integer llRound(float number);

For example:
integer number = llRound(llFrand(5) + 1);


So to apply this to a random delay, you will just need to do something like:
llSetTimerEvent(llFrand(5) + 1);

This will create a timer event that occurs every 1 to 5 seconds.
a lost user
Join date: ?
Posts: ?
08-13-2005 21:32
Wonderful! Thanks so much! =D
Seagel Neville
Far East User
Join date: 2 Jan 2005
Posts: 1,476
08-13-2005 21:46
From: Gaz Hornpipe
If you need to get a number between 1 and 5, use this:
float number = llFrand(5) + 1;
llFrand(4) + 1; ;)
_____________________
:) Seagel Neville :)