jon93
New Member
Posts: 15
|
Post by jon93 on Nov 21, 2022 0:10:35 GMT
Hello everyone, I am playing with a meaningless simple program in which a ball bounces randomly inside a box trying to find the quickest way to a target. I have found something strange about "randomize". I want to start ball bouncing sequence with different randomize seeds and then select which one works best. So at the start of each run I increase the randomize seed. But when I increase the randomize seed the pattern of bouncing of the ball in the box is almost the same as the previous one. It drove me a little crazy for several hours. I assumed I was making a mistake. But now I see that if the randomize seed is increased by only a very small amount like .0000001 the numbers generated by one sequence of rnd are almost the same as the previous one.
If the rnd sequence runs through many iterations (5000) the two sequences are different.
Have others noticed this before?
Jon, in Ottawa, Canada.
RandomizerSeed = .1 HowMuchToIncreaseRandimizerSeed = .0000001 ' if this is much bigger the sameness effect does not happen. for i = 1 to 5 RandomizerSeed = RandomizerSeed + HowMuchToIncreaseRandimizerSeed randomize RandomizerSeed print 'for j = 1 to 500 'run this loop to go further along the rnd sequence; different sequences of rnd then become different. 'dummy = rnd(1) 'next print "RandomiserSeed", RandomizerSeed for k = 1 to 5 print k, rnd(1) next k next i
|
|
|
Post by plus on Nov 21, 2022 1:08:08 GMT
Plenty of complaints about JB's random number generator but what it has to do with bouncing balls is beyond me!
You can look into building your own random number generator but first are your expectations realistic and properly reasoned?
Randomize seed ' will produce same sequence of numbers from start to however long it goes
If the sequence values aren't random enough, store them all in a container and shuffle it.
'repeatable sequences seed1 = .5065 seed2 = .7077 randomize seed1 Dim rn(5000) for i = 0 to 5000 rn(i) = rnd(1) next randomize seed2 for i = 5000 to 1 step -1 r = int(rnd(1)*(i+1)) t = rn(i) rn(i) = rn(r) rn(r) = t next
for i = 1 to 100 ' go ahead and write the numbers down and run this again to compare print rn(i) next
|
|
|
Post by Rod on Nov 21, 2022 8:19:38 GMT
I am not sure how there can be a “best random sequence” but interested to see what you mean. Yes there are issues with Just BASICs pseudo random number generator but no more so than any other. Frequent restarting and small changes to the seed have been mentioned before as well as a slight bias. There are discussions to search out
I think b+ has a solution for the starting problem but then the sequence can never be repeated.
|
|
|
Post by plus on Nov 21, 2022 13:51:57 GMT
Dang! I was hoping to show you can repeat a double seeded randomized shuffle.
Some of my favorite works depend on repeatable "random" sequences because it saves so much time and space from having to store data.
|
|
|
Post by tsh73 on Nov 21, 2022 14:19:10 GMT
Here 7 set of 10 random numbers, starting from seeds 0.1+i*h with different steps, from h=0.0000001 to h=0.1 Obviously it is pretty linear with small h. But some decent h + discarding some spare RNDs makes you pretty random, I think. nomainwin K=7 N=10 seed=0.1 'h=0.0000001 h=0.1 open "test" for graphics_nsb_nf as #gr #gr "trapclose [quit]" #gr "down"
x0=10 y0=310 scale=300 #gr "\\";" h=";h #gr "size 2" '#gr "home" '#gr "line ";;" ";;" ";;" "; #gr "line ";x0;" ";y0;" ";x0+scale;" ";y0 #gr "line ";x0;" ";y0;" ";x0;" ";y0-scale #gr "north; turn -90" 'up
for k = 1 to K seed1=seed+k*h randomize seed1 #gr "color ";word$("pink red brown yellow green cyan blue", k)
for i = 1 to N hh=scale/N xx=x0+i*hh yy=y0-scale*rnd(0) #gr "line ";xx+3*k;" ";y0;" ";xx+3*k;" ";yy next next
#gr "flush" wait
[quit] close #gr end
|
|
jon93
New Member
Posts: 15
|
Post by jon93 on Nov 21, 2022 17:13:29 GMT
Thanks for shuffle idea and info I was thinking of writing my own rnd generator using prime numbers . Re "what it has to do with bouncing balls" you have to understand the utterly trivial, physically impossible and absurd nature of my ball box. I write it for brain challenge. I wrote code for a ball bouncing in a box. boring. make the bounce random directions (physically absurd). Then see how long it takes to reach a target. Then select the best route. You will grasp the idea once you realise how pointless it is! If you try to find meaning or usefulness in it you will just be confused.
Jon
|
|
|
Post by tsh73 on Nov 21, 2022 21:14:07 GMT
|
|