Answered by:
random decimal number
Question

hi there! i need to know if its possible to get a random decimal number? like this for example:
math.getrandomnumber(5)
'somehow to get one of those numbers:
1/1,2/1,3/1,4/1,5.... 2,1/2,2/..... 4,8/4,9/5
is that possible? i need those numbers because i want to make my "physics" objects fly around more randomly, because else, you'll see where they wont land, and thats between the landing points of and object with speed1 and speed2 forexample. to get more precise physics, you know...
i hope someone can help!
Live for nothing, OR CODE FOR SOMETHING!Saturday, September 12, 2009 10:58 AM
Answers

math.getrandomnumber(n) is a random number between 1 and n.
We should choose n to be the total number of possible numbers we want.
So say we want between 5 and 5, with interval 0.1 : 5.0 4.9 4.8 ... 4.7 4.8 4.9 5.0
In this series there are 101 numbers  think 0.1 to 5.0, 0.1 to 5.0 and 0.0
So n = 101.
Next we want to scale the interval to 0.1, so we get : 0.1*Math.GetRandomNumber(101) : 0.1 0.2 0.3 ... 10.1
Finally we want to offset to start at 5, hence 0.1*Math.GetRandomNumber(101)5.1
So we have in general:
x = scale*Math.GetRandomNumber(count)+offest
where count is the number of points, scale is the step size, and offset gets the start point right. Marked as answer by Dudeson Saturday, September 12, 2009 12:52 PM
Saturday, September 12, 2009 12:00 PM
All replies

Try
x = 0.9+0.1*math.getrandomnumber(41)Saturday, September 12, 2009 11:06 AM 
coool! but what would it look like if it would be from 5 to 5 for example. or what did you calculate? so i can do it by myself.. thx man!
Live for nothing, OR CODE FOR SOMETHING!Saturday, September 12, 2009 11:45 AM 
math.getrandomnumber(n) is a random number between 1 and n.
We should choose n to be the total number of possible numbers we want.
So say we want between 5 and 5, with interval 0.1 : 5.0 4.9 4.8 ... 4.7 4.8 4.9 5.0
In this series there are 101 numbers  think 0.1 to 5.0, 0.1 to 5.0 and 0.0
So n = 101.
Next we want to scale the interval to 0.1, so we get : 0.1*Math.GetRandomNumber(101) : 0.1 0.2 0.3 ... 10.1
Finally we want to offset to start at 5, hence 0.1*Math.GetRandomNumber(101)5.1
So we have in general:
x = scale*Math.GetRandomNumber(count)+offest
where count is the number of points, scale is the step size, and offset gets the start point right. Marked as answer by Dudeson Saturday, September 12, 2009 12:52 PM
Saturday, September 12, 2009 12:00 PM 
cool thx! i needed this because i want to code an emitter. thx!!
Live for nothing, OR CODE FOR SOMETHING!Saturday, September 12, 2009 12:52 PM