|
| 31 Jul 2016 10:27 PM |
So I am trying to keep multiple AI ran by the same main scripts but I encountered an annoying problem.
Math.random(min,max)
It worked but it does not produce accurate results
for example:
print(math.random(20,70)) all it keeps returning is
60 60 60 60 60 60 59 59 60 59 60 each time i run it
only 2 numbers came out even though i called math.randomseed(tick()) before it
Is there a more random method? |
|
|
| Report Abuse |
|
|
| |
|
|
| 31 Jul 2016 10:32 PM |
math.random(math.random(min,max),math.random(min,max))
|
|
|
| Report Abuse |
|
|
Pxkez
|
  |
| Joined: 24 Sep 2015 |
| Total Posts: 1066 |
|
|
| 31 Jul 2016 10:37 PM |
local lastvalue=nil local start =10 local End = 20
function RandomNumber(strt,fin) local value=nil if lastvalue~=nil then while true do wait() value=math.random(strt,fin) if value~=lastvalue then break end end elseif lastvalue==nil then value=math.random(strt,fin) end lastvalue=value return value end
for i = 1,10 do print(RandomNumber(start,End)) end
-- [[you may be asking yourself, " Is this skrub an idiot did he seriously just type 25 lines to find a better solution than 1 line " , and you're completely right. ]] |
|
|
| Report Abuse |
|
|
|
| 31 Jul 2016 11:21 PM |
| @Pxkez I could be wrong but it looks like you're making a random number generator that isn't random. |
|
|
| Report Abuse |
|
|
Vezious
|
  |
| Joined: 09 Nov 2013 |
| Total Posts: 606 |
|
|
| 31 Jul 2016 11:31 PM |
| There is no such thing as random. But there are close enough ways. |
|
|
| Report Abuse |
|
|
Tynezz
|
  |
| Joined: 28 Apr 2014 |
| Total Posts: 4945 |
|
| |
|
Vezious
|
  |
| Joined: 09 Nov 2013 |
| Total Posts: 606 |
|
|
| 31 Jul 2016 11:35 PM |
D:
Explain yourself porfavor. |
|
|
| Report Abuse |
|
|
| |
|
|
| 31 Jul 2016 11:37 PM |
In a universe defined by laws you're going to be hard pressed to find something truly random. I doubt even radioactive decay is random, but I mean sure anything can happen.
|
|
|
| Report Abuse |
|
|
|
| 31 Jul 2016 11:38 PM |
| No matter what,there is nothing that is fully random. |
|
|
| Report Abuse |
|
|
Tynezz
|
  |
| Joined: 28 Apr 2014 |
| Total Posts: 4945 |
|
|
| 31 Jul 2016 11:39 PM |
random.org
"RANDOM.ORG offers true random numbers to anyone on the Internet. The randomness comes from atmospheric noise, which for many purposes is better than the pseudo-random number algorithms typically used in computer programs. " |
|
|
| Report Abuse |
|
|
|
| 31 Jul 2016 11:40 PM |
There are basically 2 kinds of RNG
PRNG (what everyone generally uses) CSPRNG (Cryptographically Secure, unpredictable, about as close to true randomness as is allowed by science)
Which may include random bit generators in their operation
DRBG HMAC_DRBG Dual_EC_DRBG (Never use these if you can help it)
And others that I know nothing about. My point is unless you've got an entropy harvesting daemon with enough resources to produce reasonable randomness, just use math.random or another PRNG.
Btw never set math.randomseed multiple times, especially if you're pulling random values immediately afterwards on each occasion. Then it's very predictable. |
|
|
| Report Abuse |
|
|
|
| 31 Jul 2016 11:41 PM |
It's still not truly random though. Weather isn't truly random, dice rolls aren't truly random, spinners aren't truly random, coin flips aren't truly random. It's all based on physics, which is just laws.
|
|
|
| Report Abuse |
|
|
|
| 31 Jul 2016 11:41 PM |
| Just because they use an algorithm that is complex doesn't mean it's truly random.Though what they offer might be better than ‘pseudo-random’ it doesn't mean they are truly random. |
|
|
| Report Abuse |
|
|
Tynezz
|
  |
| Joined: 28 Apr 2014 |
| Total Posts: 4945 |
|
|
| 31 Jul 2016 11:42 PM |
What is random? Something you cannot predict, therefore, random. But yeah, dies aren't random, mostly everything has its reason. |
|
|
| Report Abuse |
|
|
|
| 31 Jul 2016 11:44 PM |
That makes sense Tynezz, but still, math.random can only really be predicted by a computer...
|
|
|
| Report Abuse |
|
|
|
| 31 Jul 2016 11:44 PM |
| Just because you can't predict it doesn't mean it's random.Though it might be hard to tell,they are made of only algorithms which are repeated. |
|
|
| Report Abuse |
|
|
Tynezz
|
  |
| Joined: 28 Apr 2014 |
| Total Posts: 4945 |
|
| |
|
Tynezz
|
  |
| Joined: 28 Apr 2014 |
| Total Posts: 4945 |
|
|
| 31 Jul 2016 11:45 PM |
@arsh, so what is random? Is it something without reason? Is it something with no purpose? Is it something that is completely unpredictable? |
|
|
| Report Abuse |
|
|
Cuyler
|
  |
| Joined: 27 Feb 2006 |
| Total Posts: 3784 |
|
|
| 31 Jul 2016 11:48 PM |
With enough computational power, everything can be analyzed and predicted. Randomness is only our own ignorance. For the most part, however, what we use for "randomness" in computers works well enough, because it's hard for a brain to predict it.
To answer the op's question, you could try doing this at the beginning of your script: math.randomseed(tick()) --//Sets the math.random seed to the current tick.
(Studio will give you the same numbers in play solo, because it's trying to give you consistent results. Test your script in a published place over and over, and it shouldn't be the same.)
|
|
|
| Report Abuse |
|
|
|
| 31 Jul 2016 11:48 PM |
CSPRNGs are designed to be better, more random, with an enormous amount of entropy both input and output. They get by all the common shortcomings of regular PRNGs. Unfortunately the key to their success is having a perfect source of randomness, which is impossible. So the bigger your machine, the more data it processes, the more programs run, etc, will increase the effectiveness of entropy harvesting.
But Roblox doesn't give us good enough randomness. That's why I made my own RNG. It's still powered by math.random but it reseeds using a sine function that calculates something to do with the difference between tick and os.time. I seem very unsure of that because I don't remember exactly how it works. |
|
|
| Report Abuse |
|
|
|
| 31 Jul 2016 11:49 PM |
| unpredictability has nothing to do with it.Like already stated a human can't fully predict the outcome of a dice every time,though it not random overall,to the human it may seem so. |
|
|
| Report Abuse |
|
|
|
| 31 Jul 2016 11:49 PM |
@Cuyler That right there is one of the greatest quotes I've ever heard of
"Randomness is only our own ignorance." |
|
|
| Report Abuse |
|
|
|
| 31 Jul 2016 11:50 PM |
"Randomness is only our own ignorance" I would use "finite minds", or perhaps "finite minds allocating resources to more important things like dodging traffic yet aren't suited to figuring it out even if we weren't so ignorant".
|
|
|
| Report Abuse |
|
|