Naw, I think we're going on the wrong track. First off, try to reseed often, within the loop, and the same pattern soon occurs.I disagree with the answer in its entirety.
The problem has nothing to do with the PRNG. It has everything to do with the fact that Rnd creates numbers in the range 0 to <1. An then, you are adding 20 to that random number.
Well, 20 + Rnd will hardly be all over the map!!
I disagree with the answer in its entirety.
Reseeding a random number generator with numbers from that generator is really Not A Good Idea.
Your options for better randomness are:
- Implement your own random number generator. Algorithms for such are available on the internet and should be able to give decent performance with not too large an implementation.
Rem Program creates dots using random x and y coordinates
Rem -------
Do
Call Initialize
Call DrawDots
Loop
End
Sub Initialize
_Title "Random Number Distribution"
Screen _NewImage(840, 480, 12)
Cls
End Sub
Sub DrawDots
Randomize Timer
Color 9
Print "First random number this cycle"; Rnd
Do
x = Rnd * 840
y = Rnd * 480
Circle (x, y), 1, 14
_Delay .005
If InKey$ = Chr$(27) Then Exit Do
Loop
Cls
Locate 15, 35
Input "Start with new seed (y/n)"; cont$
If cont$ = "n" Then End
End Sub
Screen 12
Do
x = Rnd * _Width
y = Rnd * _Height
c = Rnd * 16
q = Rnd
PSet (x, y), c
_Limit 10000
Loop
Screen 12
Do
x = Rnd * _Width
y = Rnd * _Height
Circle (x, y), 1, 15
Rem c = Rnd * 16
Rem q = Rnd
Rem PSet (x, y), c
_Limit 10000
Loop
This is more of a math/randomize question I suppose. I didn't go very far in math, so if someone could explain this to me in a layman way why this occurs, I'll be thanking you.
I am playing around making what I think are random pattern makers, but over time this creates an organized pattern on the screen. Why is that?
Run this for a little while, and slowly it makes organized stripes on the screen. Shouldn't it remain a random mess?
- Dav
Code: QB64: [Select]
Your swap array does prevent the pattern.
So, I'm not exactly sure of the definition of "True Random". It would seem to me that repeat numbers HAVE to be as a result of the size of a SET of numbers. No matter what the Set size is, eventually you would have to accept a repeat of a number or group of numbers. If set size dictates repeats and True Randomness excludes a repeat of a number then either the set size has to be infinity or the Random function must be set to cease/end at the first repeated number.
True random could repeat numbers million times, but not usually.
Just shuffle your deck between every call, too bad for card counters ;-))
Screen _NewImage(840, 480, 12)
Randomize Timer
Do
x = Rnd * _Width
y = Rnd * _Height
c = Rnd * 16
q = Rnd
Rem r = Rnd
Rem s = Rnd
PSet (x, y), c
If InKey$ = Chr$(27) Then End
_Limit 10000
Loop
End
(a) eliminate the one, useless, q = Rnd, or
Random number generator patterns are susceptible to 2's (read in wiki) when having one of these discussions on another forum. Notice Luke's q makes the number of calls even every cycle.
wiki suggests for heads tails if rnd repeats last head or tail to take the next flip as the official one, something like that.
Screen _NewImage(840, 480, 12)
Rem -------
Rem Moral of the story: make sure *not* to define a power of 2, as total
Rem number of random variables in the loop. Test this with 4 or 8 Rnd
Rem variables, and you sill see diagonal patterns in the image.
Rem -------
Randomize Timer
Do
x = Rnd * _Width
y = Rnd * _Height
z = 420 + Rnd * 420
w = Rnd * _Height
c = 1 + Int(Rnd * 15)
q = Rnd
r = Rnd
s = Rnd
Rem t = Rnd
Rem u = Rnd
PSet (x, y), c
PSet (z, w), c
If InKey$ = Chr$(27) Then End
_Limit 10000
Loop
End
I have to ponder on your suggestion, Steve.
In the meantime, here's demo, split screen, where the left side sees the looping Rnd variables to be non-power-of two, while the right side sees 8 Rnd variables in the loop.
But puzzle me this: Why does the right side appear to be a lighter color, overall? If you use _Height and _Width, to size the screen, the result looks darker, than if you use the actual pixel count. Rewrite the right side, using
z = (_Width / 2) + (420 * Rnd)
and you will see both sides equally dark. Weird.Code: [Select]Screen _NewImage(840, 480, 12)
Rem -------
Rem Moral of the story: make sure *not* to define a power of 2, as total
Rem number of random variables in the loop. Test this with 4 or 8 Rnd
Rem variables, and you sill see diagonal patterns in the image.
Rem -------
Randomize Timer
Do
x = Rnd * _Width
y = Rnd * _Height
z = 420 + Rnd * 420
w = Rnd * _Height
c = 1 + Int(Rnd * 15)
q = Rnd
r = Rnd
s = Rnd
Rem t = Rnd
Rem u = Rnd
PSet (x, y), c
PSet (z, w), c
If InKey$ = Chr$(27) Then End
_Limit 10000
Loop
End
You have x over the whole width and z over 2nd half, so 2nd half gets more, about 1/2 of x was supposed to get.
Pete would tell you it's a half-width idea ;-))
There is something in QB64's nature that always *seemed* random, the starting window position. Maybe can use it as a random seed number.
Every 16, 777, 216 numbers repeats. That's 2^24, and it explains why it's so easy to replicate with "powers of 2", as you guys were looking at. It'll repeat with other values as well, but it's just not as obvious plotting it, as I tried to show you with a minimal 4-number repeating data set. ;)
This 2 thing for random numbers might come from fact that 2 is most used lowest prime number factoring the most numbers.
Only one even prime and yet it factors 1/2 all numbers >= sum of all the numbers with odd prime as lowest factor.