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.randomseed(tick()) & math.random()

Previous Thread :: Next Thread 
Raphael7 is not online. Raphael7
Joined: 03 Dec 2008
Total Posts: 2479
06 Aug 2016 08:50 PM
This is a continuation from this post, https://forum.roblox.com/Forum/ShowPost.aspx?PostID=195486050

I decided to make it simpler, I'm running this code on Command Bar.


math.randomseed(tick())

local list = {}

for _, v in pairs(game.ServerScriptService:GetChildren()) do
table.insert(list, v.Name)
end

for i = 1, 10 do
print(math.random(1, #suits))
end
Report Abuse
Raphael7 is not online. Raphael7
Joined: 03 Dec 2008
Total Posts: 2479
06 Aug 2016 08:53 PM
Sorry typo @ #suits. Accidentally posted the post.

Basically when you try this code, the first number it prints will be the same everytime you run the code. You can change the path, just as long as there the table list contains something. I'm currently stumped, and I don't know how to fix this.
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
06 Aug 2016 08:53 PM
What is "suits"? Because you didn't define it here.


Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
06 Aug 2016 08:55 PM
Fine, whatever, ninja me if you're going to. See if I care.

:(









And the first number is always the same because you are just using tick(). tick by itself doesn't change drastically enough to affect the outcome of the first one or two results for a little while.
math.randomseed(tick()%1*1e7)


Report Abuse
Casualist is not online. Casualist
Joined: 26 Jun 2014
Total Posts: 4443
06 Aug 2016 09:01 PM
This problem is explained pretty well here: http://forum.roblox.com/Forum/ShowPost.aspx?PostID=175210875&PageIndex=2
math.randomseed(tick()) is fine if you understand how it works, so when you publish your game you//players won't really run into this problem (since they won't be starting a server//reseeding a lot within a short time frame//etc.). If you don't really want to understand how it works and just want something to work use math.randomseed(tick()%1*1e7). You should only ever need to seed once.

math.randomseed(tick()%1*1e7)

local list = {}

for _, v in pairs(game.ServerScriptService:GetChildren()) do
table.insert(list, v.Name)
end

for i = 1, 10 do
print(math.random(1, #suits))
end
Report Abuse
Raphael7 is not online. Raphael7
Joined: 03 Dec 2008
Total Posts: 2479
06 Aug 2016 10:14 PM
What I don't understand is when I used;

math.randomseed(tick())
print(math.random(5))

It prints random numbers from the beginning, but the moment I do something like the example above except used with this;

list = {'hi', 'hello', 'bye', 'goodbye', 'wot'}
math.randomseed(tick())
print(math.random(#list))

It doesn't work like the first example I showed, instead it prints the number 1. Why do these two cases give different results, when just looking at it, it looks similar.
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