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: Math.Random is not so random

Previous Thread :: Next Thread 
Firebeats121 is not online. Firebeats121
Joined: 02 Dec 2011
Total Posts: 1728
04 Aug 2015 12:14 AM
In studio it is truly random, but when it hits server side it ALWAYS hits 2 everytime the server starts up, its 2.

I have no idea.

Math = math.random(5)

while game.Players.NumPlayers >= 2 do
if Math == 1 then
FirstSong:Play()
elseif Math == 2 then
SecondSong:Play()
elseif Math == 3 then
ThirdSong:Play()
elseif Math == 4 then
FourthSong:Play()
elseif Math == 5 then
FifthSong:Play()
end
end
Report Abuse
Funse is not online. Funse
Joined: 11 Jun 2012
Total Posts: 7887
04 Aug 2015 12:16 AM
math.randomseed(tick())
Report Abuse
robomax11 is not online. robomax11
Joined: 07 Jul 2011
Total Posts: 6828
04 Aug 2015 12:21 AM
puesdo random number generator

you can't be truly random.

just unpredictability


love me
Report Abuse
Firebeats121 is not online. Firebeats121
Joined: 02 Dec 2011
Total Posts: 1728
04 Aug 2015 12:37 AM
Ok I got it to give me random numbers, but I can't put those numbers in variables
Report Abuse
Firebeats121 is not online. Firebeats121
Joined: 02 Dec 2011
Total Posts: 1728
04 Aug 2015 01:24 AM
To reword this. I have got it to truly be random, the problem is, now I can't play my music.
Report Abuse
Sevrick is not online. Sevrick
Joined: 22 Oct 2013
Total Posts: 3846
04 Aug 2015 01:36 AM
use a table
Report Abuse
Firebeats121 is not online. Firebeats121
Joined: 02 Dec 2011
Total Posts: 1728
04 Aug 2015 01:56 AM
???
Report Abuse
Tuneable is not online. Tuneable
Joined: 16 Feb 2013
Total Posts: 2932
04 Aug 2015 01:58 AM
math.randomseed(tick())

local Math = math.random(5)

while game.Players.NumPlayers >= 2 do
if Math == 1 then
FirstSong:Play()
elseif Math == 2 then
SecondSong:Play()
elseif Math == 3 then
ThirdSong:Play()
elseif Math == 4 then
FourthSong:Play()
elseif Math == 5 then
FifthSong:Play()
end
Math = math.random(5)
end
Report Abuse
Firebeats121 is not online. Firebeats121
Joined: 02 Dec 2011
Total Posts: 1728
04 Aug 2015 02:11 AM
I keep getting a set number. I heard this changes with each server though. Is that true?
Report Abuse
Firebeats121 is not online. Firebeats121
Joined: 02 Dec 2011
Total Posts: 1728
04 Aug 2015 02:19 AM
Ok so now it is "randomized" to hit 1 and 5 now.


It skips 2 3 4

math.random(tick())
Math = math.random(5)


while game.Players.NumPlayers >= 2 do
if Math == 1 then
FirstSong:Play()
elseif Math == 2 then
SecondSong:Play()
elseif Math == 3 then
ThirdSong:Play()
elseif Math == 4 then
FourthSong:Play()
elseif Math == 5 then
FifthSong:Play()
end
end
Report Abuse
mycheeze is not online. mycheeze
Joined: 27 Jun 2011
Total Posts: 6748
04 Aug 2015 02:51 AM
r u srs, you forgot the wait()

local T = {FirstSong, SecondSong, ThirdSong, FourthSong, FithSong}

while game.Players.NumPlayers >= 2 do wait(15) T[math.random(1, #T)]:Play() end
Report Abuse
mycheeze is not online. mycheeze
Joined: 27 Jun 2011
Total Posts: 6748
04 Aug 2015 02:53 AM
oh and don't use the ugly math.randomseed(tick())

math.random() is as random as it gets
Report Abuse
FactualTheory is not online. FactualTheory
Joined: 10 Sep 2013
Total Posts: 1365
04 Aug 2015 02:54 AM
IT is random lol.

You could do math.randomseed or wth it is

or you could

repeat
thing1 = game.Players:GetChildren()[math.random(1, #game.Players:GetChildren()]
if thing.name = script.prev.Value then
local thing1 = game.Players:GetChildren()[math.random(1, #game.Players:GetChildren()]
until thing.name ~= script.prev.Value

script.prev.Value = thing1.name

MIND the spelling errors

can't be fked to check over.
Report Abuse
Tycooons is not online. Tycooons
Joined: 13 Aug 2014
Total Posts: 5871
04 Aug 2015 02:55 AM
local Choice = {
"FirstSong",
"SecondSong",
"ThirdSong",
"FourthSong",
"FifthSong"
};

randNum = Math.random(5);

while game.Players.NumPlayers >= 2 do
local Song = Choice[randNum]
Song:Play()
end
Report Abuse
mycheeze is not online. mycheeze
Joined: 27 Jun 2011
Total Posts: 6748
04 Aug 2015 02:58 AM
Look at all of these imbeciles forgetting the wait in there loops :V
Report Abuse
FactualTheory is not online. FactualTheory
Joined: 10 Sep 2013
Total Posts: 1365
04 Aug 2015 03:28 AM
THATS WHAT AUTO SAVES ARE FOR

I even sed i forgot sum things :P
Report Abuse
lateregistration is not online. lateregistration
Joined: 02 Apr 2013
Total Posts: 2630
04 Aug 2015 03:31 AM
local choices = 5
local randChoice = math.abs(math.random(1, choices) - tick()%choices)
Report Abuse
FactualTheory is not online. FactualTheory
Joined: 10 Sep 2013
Total Posts: 1365
04 Aug 2015 03:33 AM
random.seed or whtever the f it is is NOT RANDOM!

it doesn't RANDOMLY chooses any member of a list, therefore its not random.
Report Abuse
LegendaryAccount is not online. LegendaryAccount
Joined: 02 Jun 2010
Total Posts: 13193
04 Aug 2015 03:33 AM
Try this and this will show you what you are doing wrong


---------------------------------------------
Math = math.random(10)

for i = 1,10 do
print(Math)
end

wait(5)---------------------------------------------

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

---------------------------------------------
Report Abuse
mycheeze is not online. mycheeze
Joined: 27 Jun 2011
Total Posts: 6748
04 Aug 2015 03:34 AM
Just use mine alredy :V

local T = {FirstSong, SecondSong, ThirdSong, FourthSong, FithSong}

while game.Players.NumPlayers >= 2 do wait(15) T[math.random(1, #T)]:Play() end
Report Abuse
Firebeats121 is not online. Firebeats121
Joined: 02 Dec 2011
Total Posts: 1728
04 Aug 2015 11:09 AM
I'd never thought it would be this much trouble.

I got rid of math.randomseed(tick()) due to people saying its useless. This is my new code
However note that this crashes my game, after when everything is completed and its trying to recall "Math" to play the song.



Math = math.random(5)

for i = 1,5 do
print(Math)
end

wait(5)

for i = 1,10 do
Math = math.random(5)
wait(1)
print(Math)
end

print(Math)

while game.Players.NumPlayers >= 1 do
if Math == 1 then
FirstSong:Play()
elseif Math == 2 then
SecondSong:Play()
elseif Math == 3 then
ThirdSong:Play()
elseif Math == 4 then
FourthSong:Play()
elseif Math == 5 then
FifthSong:Play()
end
end
Report Abuse
Firebeats121 is not online. Firebeats121
Joined: 02 Dec 2011
Total Posts: 1728
04 Aug 2015 11:24 AM
Also a fun little note, if I put another Math = math.random(5) in the while statement it plays all the songs :P
Report Abuse
Firebeats121 is not online. Firebeats121
Joined: 02 Dec 2011
Total Posts: 1728
04 Aug 2015 01:13 PM
It keeps crashing.... halp
Report Abuse
Firebeats121 is not online. Firebeats121
Joined: 02 Dec 2011
Total Posts: 1728
04 Aug 2015 01:23 PM
alright I switched back to this

math.randomseed(tick())
Math = math.random(5)

while game.Players.NumPlayers >= 2 do
if Math == 1 then
FirstSong:Play()
elseif Math == 2 then
SecondSong:Play()
elseif Math == 3 then
ThirdSong:Play()
elseif Math == 4 then
FourthSong:Play()
elseif Math == 5 then
FifthSong:Play()
end
end



IT IS DISPLAYING THE NUMBER BUT ITS NOT PLAYING THE MUSIC even when i set the numplayers to >= 1
Report Abuse
lateregistration is not online. lateregistration
Joined: 02 Apr 2013
Total Posts: 2630
04 Aug 2015 08:56 PM
Math = math.abs(math.random(1, 5) - tick()%5)


while game.Players.NumPlayers >= 2 do
if Math == 1 then
FirstSong:Play()
elseif Math == 2 then
SecondSong:Play()
elseif Math == 3 then
ThirdSong:Play()
elseif Math == 4 then
FourthSong:Play()
elseif Math == 5 then
FifthSong:Play()
end
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