Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to get truly random numbers?

math.random does NOT get a near to random number. My game uses math.random for gamemodes and the games modes happen in the same order every single time I play! How do i get it so its not sequenced? The pattern i have is that it picks "5" then "12" and then "12" again. For proof play my game http://www.roblox.com/games/342247316/Tile-Trouble-Alpha#!/game-instances and you will see the pattern.

function ReplicateText(text)
	for i,v in pairs(game.Players:GetPlayers()) do
		v.PlayerGui.Countdown.Number.Text = text
	end
end
while true do
	t = 60
	ranNum = math.random(1,12)
	if ranNum == 5 then
		map = "Green"
		game.ServerStorage.GreenPlates:Clone().Parent = game.Workspace
	elseif ranNum == 2 then
		map = "Red"
		game.ServerStorage.RedPlates:Clone().Parent = game.Workspace
	elseif ranNum == 3 then
		map = "Ultimate Speed"
		t = 30
		game.ServerStorage.Speed:Clone().Parent = game.Workspace
		game.ServerStorage.YellowPlates:Clone().Parent = game.Workspace
	elseif ranNum == 4 then
		map = "3 Layers Green"
		t = 120
		game.ServerStorage.GreenPlate3:Clone().Parent = game.Workspace
	elseif ranNum == 6 then
		map = "3 Layers Speed"
		game.ServerStorage.Speed:Clone().Parent = game.Workspace
		game.ServerStorage.SpeedPlate3:Clone().Parent = game.Workspace
		t = 80
	elseif ranNum == 1 then
		map = "Icy"
		game.ServerStorage.IcePlate:Clone().Parent = game.Workspace
	elseif ranNum == 7 then
		map = "Disappearing"
		game.ServerStorage.DisappearingPlate:Clone().Parent = game.Workspace
	elseif ranNum == 8 then
		t = 80
		game.ServerStorage.JumpDecal:Clone().Parent = game.Workspace
		map = "Anti-Gravity"
		game.ServerStorage.JumpyPlate:Clone().Parent = game.Workspace
		game.ServerStorage.Jump:Clone().Parent = game.Workspace
	elseif ranNum == 9 then
		map = "Sword Fight"
		game.ServerStorage.JumpyPlate:Clone().Parent = game.Workspace
		game.ServerStorage.Sword:Clone().Parent = game.Workspace
	elseif ranNum == 10 then
		t = 80
		map = "Spork Mania"
		game.ServerStorage.PinkPlate3:Clone().Parent = game.Workspace
		game.ServerStorage.Spork:Clone().Parent = game.Workspace
	elseif ranNum == 11 then
		t = 80
		game.ServerStorage.JumpDecal:Clone().Parent = game.Workspace
		map = "Double Trouble!" --Anti Grav and disappearing
		game.ServerStorage.DisappearingPlate:Clone().Parent = game.Workspace
		game.ServerStorage.Jump:Clone().Parent = game.Workspace
	elseif ranNum == 12 then
		map = "Double Trouble!" --Icy and speedy
		t = 30
		game.ServerStorage.SpeedDecal:Clone().Parent = game.Workspace
		game.ServerStorage.IcePlate:Clone().Parent = game.Workspace
		game.ServerStorage.Speed:Clone().Parent = game.Workspace
	else
		map = "Fixing the game"
	end


	for i = 10, 1, -1 do
		ReplicateText("Starting in "..i)
		wait(1)
	end
	ReplicateText("Map: "..map)
	wait(5)
	ReplicateText("Go!")
	game.Workspace.FallBlock.CanCollide = false
	wait(1)
	game.Workspace.FallBlock.CanCollide = true
	for i = t, 1, -1 do
		ReplicateText(i)
		wait(1)
	end
	ReplicateText("Finish")
	if ranNum == 5 then
		game.Workspace.GreenPlates:Destroy()
		game.ServerStorage.WinBlock:Clone().Parent = game.Workspace
	elseif ranNum == 2 then
		game.Workspace.RedPlates:Destroy()
		game.ServerStorage.WinBlock:Clone().Parent = game.Workspace
	elseif ranNum == 3 then
		game.Workspace.YellowPlates:Destroy()
		game.Workspace.Speed:Destroy()
		game.ServerStorage.WinBlock:Clone().Parent = game.Workspace
	elseif ranNum == 4 then
		game.Workspace.GreenPlate3:Destroy()
		game.ServerStorage.WinBlock:Clone().Parent = game.Workspace
		game.Workspace.WinBlock.CFrame = game.Workspace.WinBlock.CFrame + Vector3.new(0,-103.6,0)
	elseif ranNum == 6 then
		game.Workspace.SpeedPlate3:Destroy()
		game.Workspace.Speed:Destroy()
		game.ServerStorage.WinBlock:Clone().Parent = game.Workspace
		game.Workspace.WinBlock.CFrame = game.Workspace.WinBlock.CFrame + Vector3.new(0,-103.6,0)
	elseif ranNum == 1 then
		game.Workspace.IcePlate:Destroy()
		game.ServerStorage.WinBlock:Clone().Parent = game.Workspace
	elseif ranNum == 7 then
		game.Workspace.DisappearingPlate:Destroy()
		game.ServerStorage.WinBlock:Clone().Parent = game.Workspace
	elseif ranNum == 8 then
		game.Workspace.JumpDecal:Destroy()
		game.Workspace.Jump:Destroy()
		game.Workspace.JumpyPlate:Destroy()
		game.ServerStorage.WinBlock:Clone().Parent = game.Workspace
	elseif ranNum == 9 then
		game.Workspace.Sword:Destroy()
		game.Workspace.JumpyPlate:Destroy()
		game.ServerStorage.WinBlock:Clone().Parent = game.Workspace
	elseif ranNum == 10 then
		game.Workspace.Spork:Destroy()
		game.Workspace.PinkPlate3:Destroy()
		game.ServerStorage.WinBlock:Clone().Parent = game.Workspace
		game.Workspace.WinBlock.CFrame = game.Workspace.WinBlock.CFrame + Vector3.new(0,-106.6,0)
	elseif ranNum == 11 then
		game.Workspace.JumpDecal:Destroy()
		game.Workspace.Jump:Destroy()
		game.Workspace.DisappearingPlate:Destroy()
		game.ServerStorage.WinBlock:Clone().Parent = game.Workspace
	elseif ranNum == 12 then
		game.Workspace.SpeedDecal:Destroy()
		game.Workspace.Speed:Destroy()
		game.Workspace.IcePlate:Destroy()
		game.ServerStorage.WinBlock:Clone().Parent = game.Workspace
	else
		wait(0.1)
	end
	wait(10)
	ReplicateText("Intermission")
	game.Workspace.WinBlock:Destroy()
	wait(15)
end

1 answer

✓ Accepted answer

You don't need truly random numbers, just remember to set the randomseed at the top of your script:

math.randomseed(tick()*10);

That'll sort out your script if you put it right at the top.

4 comments

0

What does this do? and why is it "10"?

0

Where do i put this seed? If i put it at the top it doesn't work and the script does not run

0

Sorry I just woke up, I forgot to call tick()

0

it worked just by doing math.randomseed(tick())

This discussion is preserved as it was. New answers, comments, and votes are closed.