|
| 19 Mar 2016 10:23 AM |
I'm trying to get a random number between 1 and 5 using this:
math.random(1, 5)
And every single time it gives me 5. So I tried randomseed(tick()) and then it gave me 3 every single time. I've run this about 20 times so far and it has given me the exact same number *every single time*.
Has this happened to anyone? |
|
|
| Report Abuse |
|
|
c9_io
|
  |
| Joined: 15 Feb 2014 |
| Total Posts: 2642 |
|
|
| 19 Mar 2016 10:24 AM |
You're probably doing something wrong. (actually yes you are)
#code "オタク" |
|
|
| Report Abuse |
|
|
|
| 19 Mar 2016 10:28 AM |
I know I'm not doing something wrong, I have isolated it down to that line. I've tried calling it from an external function, I tried using tick(), I even tried adding 1 to it just to see what it gave me and it did this:
> 6 > 6 > 6 > 6 > 6
For some reason it just won't give me a random number. |
|
|
| Report Abuse |
|
|
|
| 19 Mar 2016 10:29 AM |
| Like I know a lot of people on this forum say that and then it turns out they are, but I've been doing this for 3 years and I can't see any way that I can be writing that out wrong. |
|
|
| Report Abuse |
|
|
|
| 19 Mar 2016 10:30 AM |
Only randomseed once Also post full code |
|
|
| Report Abuse |
|
|
c9_io
|
  |
| Joined: 15 Feb 2014 |
| Total Posts: 2642 |
|
|
| 19 Mar 2016 10:30 AM |
Are you setting it as a constant or overriding it every time
#code --// オタク |
|
|
| Report Abuse |
|
|
|
| 19 Mar 2016 10:32 AM |
I'm overriding it with a new local variable, here's the full function:
function formGrid() repeat local num = math.random(1, 5) print(num) if num == 5 then done = true end until done == true end
formGrid()
Here's my Output:
> 5
The first number it goes to is 5 *every single time*. |
|
|
| Report Abuse |
|
|
|
| 19 Mar 2016 10:34 AM |
My problem was I tried to seed it every time it ran, seeding it once worked o_o
Thank you SO MUCH! |
|
|
| Report Abuse |
|
|