|
| 18 Feb 2016 10:03 AM |
So for a something I'm making I need to get a random number
the number being either 1, 2 or 3
Tried one or two "random number generators" on roblox, I just kept getting the same number over and over.
Anyone got any suggestions? |
|
|
| Report Abuse |
|
|
ownedyou1
|
  |
| Joined: 03 Jul 2008 |
| Total Posts: 528 |
|
|
| 18 Feb 2016 10:15 AM |
| local num = math.random(1,3) |
|
|
| Report Abuse |
|
|
|
| 18 Feb 2016 10:16 AM |
Been trying that but got 3 each time. Though it appears that if I include wait(1) (or just any time in general) then the numbers are random |
|
|
| Report Abuse |
|
|
|
| 18 Feb 2016 10:17 AM |
Is random for me :/
for i = 1, 10 do print(math.random(1, 3)) end
|
|
|
| Report Abuse |
|
|
ownedyou1
|
  |
| Joined: 03 Jul 2008 |
| Total Posts: 528 |
|
|
| 18 Feb 2016 10:20 AM |
local num = math.random(1,9) if num==1 or num== 2 or num == 3 then local realnum = 1 elseif num==4 or num==5, or num==6 then local realnum = 2 elseif num==7 or num==8 or num==9 then local realnum==3 else end -- your brain is a useful tool |
|
|
| Report Abuse |
|
|
| |
|
Baya
|
  |
| Joined: 16 Feb 2009 |
| Total Posts: 12044 |
|
| |
|
|
| 18 Feb 2016 11:00 AM |
I tried this, but I'm still getting the same value on each run. I'm not sure what the deal is with randomseed(), but I wasn't encountering this problem a while ago.
math.randomseed(tick())
local function RNG(Min,Max) local M = 10^(string.len(tostring(math.ceil(Max))) - 1) return (math.random(Min,Max)*M)/M end
while true do print(RNG(1,20)) wait(1) end
|
|
|
| Report Abuse |
|
|
ownedyou1
|
  |
| Joined: 03 Jul 2008 |
| Total Posts: 528 |
|
|
| 18 Feb 2016 11:20 AM |
| ..... No matter how you do it you will get the same result 1/3 == 3/9 its random just higher chance to repeat |
|
|
| Report Abuse |
|
|
|
| 18 Feb 2016 11:25 AM |
math.ceil((math.random(1,30)/10))
Picks a random number between 1 and 30, rounds it up to the nearest integer so you get 1, 2, or 3. It's the exact same odds but you'll think it's more random because math is involved. |
|
|
| Report Abuse |
|
|
ownedyou1
|
  |
| Joined: 03 Jul 2008 |
| Total Posts: 528 |
|
|
| 18 Feb 2016 01:02 PM |
| ^ thats not how math works, math is finite 1/3==3/9==10/30==100/300 you will get same even in a recent script i made i used math.random(1,21) that even returned the same number 3 times in a row i remember vividly. perhaps what you want to do is lastnum=2 num=math.random(1,3) if num~=lastnum then else end |
|
|
| Report Abuse |
|
|
chimmihc
|
  |
| Joined: 01 Sep 2014 |
| Total Posts: 17143 |
|
|
| 18 Feb 2016 01:14 PM |
Since you obviously don't want a "random" number, just a different number each time, you should do this:
local GetNumber
do local n = 0 GetNumber = function() n = n + 1 if n == 4 then n = 1 end return n end end
for i = 1,10 do print(GetNumber()) end
|
|
|
| Report Abuse |
|
|