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
We use cookies to offer you a better experience. By using Roblox.com, you are agreeing to our Privacy and Cookie Policy.
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: More "random" math.random?

Previous Thread :: Next Thread 
DurstAuric is online. DurstAuric
Joined: 12 May 2009
Total Posts: 8066
14 Jun 2016 02:04 PM
Math.random is random, but its predictable; too predictable. Is there a way to make math.random more "random" and never select the same result twice (or more) in a row?


-=[ RAP: 314,296 || DurstAuric; the narb of ROBLOX ]=-
Report Abuse
AbstractMadness is not online. AbstractMadness
Joined: 22 Dec 2014
Total Posts: 20425
14 Jun 2016 02:05 PM
put math.randomseed(tick()%69*1337/420) at the top of your script

not even joking


#code R+ | local RAP = "R$606,782"; local robux = "R$4,167"
Report Abuse
Protoduction is not online. Protoduction
Joined: 27 Jul 2012
Total Posts: 1054
14 Jun 2016 02:05 PM
math.random() returns a random number between 0-0.5

You can multiply that if you want. It'd probably be more random


Report Abuse
DurstAuric is online. DurstAuric
Joined: 12 May 2009
Total Posts: 8066
14 Jun 2016 02:09 PM
@Abstract
Lolwhat?


-=[ RAP: 314,237 || DurstAuric; the narb of ROBLOX ]=-
Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
14 Jun 2016 02:13 PM
math.randomseed(tick()) at the beginning of your code is the only thing you need for a true-enough random

This seeds math.random based off time, which is a great reference for randomness


Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
14 Jun 2016 02:15 PM
Abstract's %69*1337/420 will have virtually the same effect

all those numbers mean virtually nothing tho :)

>"virtually" intensifies


Report Abuse
AggressiveCatch is not online. AggressiveCatch
Joined: 17 Jul 2011
Total Posts: 5840
14 Jun 2016 02:15 PM
"math.randomseed(tick()) at the beginning of your code is the only thing you need for a true-enough random"

that gives you an even more predictable random
Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
14 Jun 2016 02:28 PM
Uhh duurrr so is math.randomseed(tick()%69*1337/420)



Report Abuse
membra is not online. membra
Joined: 14 Oct 2008
Total Posts: 6313
14 Jun 2016 02:29 PM
I've seen a few people fetch random numbers via random dot org using HTTP. I'm not sure if that's a smart thing to do, though.


Report Abuse
DurstAuric is online. DurstAuric
Joined: 12 May 2009
Total Posts: 8066
14 Jun 2016 03:09 PM
@Membra
And how would I do that exactly?


-=[ RAP: 314,087 || DurstAuric; the narb of ROBLOX ]=-
Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
14 Jun 2016 03:10 PM
It's not even worth it

just randomseed(tick()) bro


Report Abuse
LuaLlama is not online. LuaLlama
Joined: 25 Jan 2014
Total Posts: 1123
14 Jun 2016 03:12 PM
math.randomseed(tick()*math.random()) -- This proves that Math.random() returns a double value between 0, and 1

That might be the best way.
Report Abuse
DurstAuric is online. DurstAuric
Joined: 12 May 2009
Total Posts: 8066
14 Jun 2016 03:15 PM
Okay. If anyone is wondering, I'm using this in order to create an in-game music player which plays a random song from a table, rather than in order. From experience, math.random isn't exactly "random" so I needed a way to make it more random..


-=[ RAP: 314,061 || DurstAuric; the narb of ROBLOX ]=-
Report Abuse
AggressiveCatch is not online. AggressiveCatch
Joined: 17 Jul 2011
Total Posts: 5840
14 Jun 2016 03:15 PM
or

math.randomseed(math.random(os.time()))
Report Abuse
DurstAuric is online. DurstAuric
Joined: 12 May 2009
Total Posts: 8066
14 Jun 2016 03:28 PM
I don't think there's a difference if I use math.randomseed(math.random(os.time()) compared to math.randomseed(tick()).


-=[ RAP: 314,051 || DurstAuric; the narb of ROBLOX ]=-
Report Abuse
Flux_Capacitor is not online. Flux_Capacitor
Joined: 07 Apr 2008
Total Posts: 45720
14 Jun 2016 03:32 PM
"put math.randomseed(tick()%69*1337/420) at the top of your script"
That literally makes it worse

"math.random() returns a random number between 0-0.5"
No. Between 0-1 exclusive

"math.randomseed(tick()) at the beginning of your code is the only thing you need for a true-enough random"
IIRC Roblox already sets the seed to this when a server starts so it won't really make an actual difference. The algorithm for fetching a random number will always be the same


OP if you really care about "true randomness" then use HttpService and fetch from random dot org or soemthing.
Report Abuse
ExtremeBuilder15 is not online. ExtremeBuilder15
Joined: 01 May 2012
Total Posts: 3176
14 Jun 2016 03:39 PM
math.randomseed(tick())

local songNum = math.random(1,100)--change

Songs[songNum]:Play()

function check()
local oldNum = songNum
repeat
songNum = math.random(1,100)
until songNum ~= oldNum
end


Sloppy, but this is the general idea.
Report Abuse
Flux_Capacitor is not online. Flux_Capacitor
Joined: 07 Apr 2008
Total Posts: 45720
14 Jun 2016 03:42 PM
That's not how random works. That makes it less random.
Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
14 Jun 2016 03:45 PM
Does true randomness even exist?
Are my actions random?
Do I have free will?

AHHHH


Report Abuse
ExtremeBuilder15 is not online. ExtremeBuilder15
Joined: 01 May 2012
Total Posts: 3176
14 Jun 2016 03:46 PM
@Flux curse you randomness. You think it's the easiest subject to understand until you start studying it.
Report Abuse
killerbot29003 is online. killerbot29003
Joined: 04 Oct 2014
Total Posts: 3054
14 Jun 2016 03:52 PM
math.randomseed(os.time())

local math1 = math.random(1,10)
local math2 = math.random(1,10)

print(math1 + math2)




I dunno if that's more random, but still prints a number from 1-20.


This siggy is copyrighted ©
Report Abuse
GeniuSkill is not online. GeniuSkill
Joined: 26 Feb 2013
Total Posts: 2
14 Jun 2016 03:53 PM
Lets say I need my servers to never use the same seed so that two servers never have the same random number stream. But if the seed is tick() by default, and 2 servers are started at exactly the same time, they will have the same seed. Is this is situation where I should use random. org
Report Abuse
GeniuSkill is not online. GeniuSkill
Joined: 26 Feb 2013
Total Posts: 2
14 Jun 2016 04:03 PM
Or seed with something like ((tick()%1e6)*1e8)%1e7 so that the seeds would vary even when casted to an unsigned integer in the underlying C function?
Report Abuse
Flux_Capacitor is not online. Flux_Capacitor
Joined: 07 Apr 2008
Total Posts: 45720
14 Jun 2016 04:05 PM
It's not going to be more random. That's not going to make any noticeable difference.
Report Abuse
DurstAuric is online. DurstAuric
Joined: 12 May 2009
Total Posts: 8066
14 Jun 2016 04:17 PM
I need it to be random, but the next random number shouldn't be the same as the previous one.


-=[ RAP: 313,927 || DurstAuric; the narb of ROBLOX ]=-
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