Aaron Levy
Medicated Lately?
Join date: 3 Jun 2004
Posts: 2,147
|
07-25-2004 14:40
How do I go about getting a random number that can be -5 to +5?
The way I'm doing now is not effecient and I know there's another way, I just can't figure it out or find it. What I'm doing now is getting a random number between 1 and 5, then getting another random 50/50 result to decide if it's negative or positive. If the 50/50 result comes back as "1" then the number will be negative and I then subtract the number x2 from itself to get it's negative value.
Is there a way to just tell LSL "I want a number between -X and X" and then it gives it to you? Also, these are all floats, if that makes any difference.
|
Pete Fats
Geek
Join date: 18 Apr 2003
Posts: 648
|
07-25-2004 14:45
float random = llFrand(10) - 5;
|
Aaron Levy
Medicated Lately?
Join date: 3 Jun 2004
Posts: 2,147
|
07-25-2004 14:46
OMG that was simple. Thanks Pete. Sometimes I don't think logically, and that was perfectly logical!
|
Aaron Levy
Medicated Lately?
Join date: 3 Jun 2004
Posts: 2,147
|
07-25-2004 14:51
Except it's giving me a syntax error right before the -5 part.
|
Grim Lupis
Dark Wolf
Join date: 11 Jul 2003
Posts: 762
|
07-25-2004 15:03
From: someone Originally posted by Aaron Levy Except it's giving me a syntax error right before the -5 part. Post your code, Aaron. We can't help you debug without seeing the code.
_____________________
Grim
"God only made a few perfect heads, the rest of them he put hair on." -- Unknown
|
Malachi Petunia
Gentle Miscreant
Join date: 21 Sep 2003
Posts: 3,414
|
07-25-2004 15:08
There is a bug in the parser that binds (-5) as a unary constant and so you wind up with <exp> <exp>; which is a syntax error. Please note the space in Pete's reply "llFrand(10) - 5" where there is a space preceeding the 5.
Hope this is what the problem was.
|
Aaron Levy
Medicated Lately?
Join date: 3 Jun 2004
Posts: 2,147
|
07-25-2004 15:10
Yep, it was the space! 
|
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
|
07-25-2004 23:36
llFrand will take negative numbers as well.
-5 <= llFrand(-5) <= 0
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river. - Cyril Connolly
Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence. - James Nachtwey
|
Wednesday Grimm
Ex Libris
Join date: 9 Jan 2003
Posts: 934
|
07-26-2004 07:18
The general forumla to get a random number between x and y is
llFrand(y - x) + x;
_____________________
Sarcasm meter: 0 |-----------------------*-| 10 Rating: Awww Jeeze!
|