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 and randomseed not being as random as it used to

Previous Thread :: Next Thread 
EncodedLua is not online. EncodedLua
Joined: 02 May 2012
Total Posts: 1555
04 Aug 2016 01:47 PM
Recently in all of my scripts, whenever I use math.random() along with math.randomseed(tick()) it usually ends up picking the same thing EVERY TIME. I ran the code over and over 100+ times and it still picked the same thing over and over. How do I fix this?
Report Abuse
TurtleAndLion is not online. TurtleAndLion
Joined: 01 Mar 2012
Total Posts: 4248
04 Aug 2016 01:51 PM
while wait(1) do
print(math.random(1, 100))
end

Report Abuse
Fangous is not online. Fangous
Joined: 03 Jul 2010
Total Posts: 4448
04 Aug 2016 02:00 PM
it practice it is still very random
Report Abuse
EncodedLua is not online. EncodedLua
Joined: 02 May 2012
Total Posts: 1555
04 Aug 2016 02:00 PM
Can anyone else answer the question I stated?
Report Abuse
Kodran is not online. Kodran
Joined: 15 Aug 2013
Total Posts: 5330
04 Aug 2016 02:04 PM
Have you tried it in online mode? Also make sure you're not doing something like this:

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

because tick will return the same value and every number will be the same because you are seeding them with the same number.
Report Abuse
EncodedLua is not online. EncodedLua
Joined: 02 May 2012
Total Posts: 1555
04 Aug 2016 02:05 PM
I am running the randomseed function at the beginning of each iteration of the game loop. Each game takes a little over a minute to 2 minutes.
Report Abuse
EncodedLua is not online. EncodedLua
Joined: 02 May 2012
Total Posts: 1555
04 Aug 2016 02:06 PM
And yes, I've tried in studio and online mode.
Report Abuse
Kodran is not online. Kodran
Joined: 15 Aug 2013
Total Posts: 5330
04 Aug 2016 02:07 PM
seed once at the start of the script.

run this:
math.randomseed(tick())
for i = 1,10 do
print(math.random())
end

I assure you it will print 10 different numbers. If you seed at the start of the script and keep getting the same random numbers it's something you're doing.
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