generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Random Numbers

Previous Thread :: Next Thread 
Sargent179 is not online. Sargent179
Joined: 29 Jul 2011
Total Posts: 358
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 is not online. ownedyou1
Joined: 03 Jul 2008
Total Posts: 528
18 Feb 2016 10:15 AM
local num = math.random(1,3)
Report Abuse
Sargent179 is not online. Sargent179
Joined: 29 Jul 2011
Total Posts: 358
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
cheesecake123456 is not online. cheesecake123456
Joined: 01 Jun 2009
Total Posts: 1529
18 Feb 2016 10:17 AM
Is random for me :/

for i = 1, 10 do
print(math.random(1, 3))
end


Report Abuse
ownedyou1 is not online. 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
MightyEagleFan223 is not online. MightyEagleFan223
Joined: 24 Dec 2013
Total Posts: 813
18 Feb 2016 10:26 AM
i dont know
Report Abuse
Baya is not online. Baya
Joined: 16 Feb 2009
Total Posts: 12044
18 Feb 2016 10:48 AM
use math.random
Report Abuse
VertexArray is not online. VertexArray
Joined: 05 Jul 2014
Total Posts: 1804
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 is not online. 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
wonderful72pike is not online. wonderful72pike
Joined: 13 Jul 2010
Total Posts: 7009
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 is not online. 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 is not online. 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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image