Rand Seed
BlitzMax Forums/BlitzMax Beginners Area/Rand Seed
| ||
Is it important to set the randseed, perhaps from the system clock so your game doesn't play the same each time? |
| ||
Yes. But for error/beta playing set it to a const, so, for example the same map is generated each time |
| ||
only if you don't want your game to play the same each time. :) |
| ||
Whatever seed you choose it creates exactly the same sequence of random numbers every time, because basically it's just a fixed math operation changing the number each time you use it. As above, you'll want to vary it at runtime in order to get more random results, otherwise you will end up with familiar patterns, levels, etc ... anything using Rand or Rnd will give the same values unless you make it adaptive. |
| ||
But for error/beta playing set it to a const, so, for example the same map is generated each time great tip thanks.So do you people just do this: SeedRnd(MilliSecs()) ? |
| ||
So do you people just do this: SeedRnd(MilliSecs()) yes |
| ||
More likely I might do it more than once. SeedRnd(Rand(0,Millisecs)) would be more random. |
| ||
would be more random. About as random I would imagine, since if millisecs was at the same amount each run through fore either of those, you will still get a repeating pattern (the chances of millisecs being at the same point are of course fairly low). |
| ||
HAHAHAH @ Daniel Its just as random, because for any Millisec you would STILL get the same series. (Made me laugh tho) |
| ||
Its just as random, because for any Millisec you would STILL get the same series. No, you wouldn't get the same series, but it wouldn't be any more random. |
| ||
ok, here's as good a truly random number as you're going to need:Local s:TStream = ReadStream("http::www.random.org/cgi-bin/randnum?num=1&min=0&max=100000&col=1") Global random_seed:Int Global r:String If Not s RuntimeError("failed to retrieve a random number seed") While Not Eof(s) r:String = ReadLine(s) Wend CloseStream(s) random_seed = r.toint() Print random_seed SeedRnd(random_seed) Print Rand(0,100) End |
| ||
@Perturbatio No, you wouldn't get the same series, but it wouldn't be any more random SeedRnd(Rand(0,Millisecs))Because for any Millisec you would STILL get the same series So I was right and you were wrong ;) (I think you thought that I ment the same series as when you didnt use this method. But I didnt ;) I ment that for any MILLIsec you would get the same series. which suprisingly, is what I said. I was unfortunatly assuming that rand had already been set. If Rand is not auto set on ititialization then, Ok yes so You are right and Im not So run Print Rnd(0,10)A few times. If it gives the same number every time then I an right, if it gives a different number then you are right ;) |