123
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|720|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Socoder -> Blitz -> random number generator...

Thu, 10 Jul 2008, 21:01
Orion Pax
Ok...blitz random number generator sucks...even when seeded. So how do I over come this. I really need better random numbers.....
Fri, 11 Jul 2008, 04:34
Phoenix
In what way does it suck? I don't see any problem with it.
Fri, 11 Jul 2008, 04:56
mike_g
There is a bias to low order bits. To get a better distribution you should generate numbers using high order bits then shift them down to the range you want.

Another, slow, but effective alternative is to keep getting numbers in a loop until one appears that is in the range you want.

Here some examples:

I havent tested them but it should give you an idea.
Fri, 15 Aug 2008, 23:05
Evil Roy Ferguso
I recently wrote a DLL wrapper for the Mersenne Twister random number generator for my own project, since with one given seed, Blitz's rand() produces consistent numbers on one computer, but it's not consistent between computers, and I need it to be.

Here's the zip, which contains the DLL and the .decls file -- stick them in your userlibs folder, and distribute mtrandom.dll with your program. It's 15KB, which shouldn't be too huge.

Functions available are mtSeedRnd(), mtRand(), mtRnd(), and mtRawRand().

mtSeedRnd() works as expected. mtRand() does, too, more or less, but with the notable exception that it will barf if max is less than min or 0. mtRnd() is the oddball - it always returns a result in the range [0, 1]. To simulate Blitz's Rnd() behavior, try mtRand(min, max - 1) + mtRnd(). mtRandRaw() returns a random number in [-2,147,483,648, 2,147,483,647].

As a bonus, it's marginally (read: negligibly) faster than the "real" Blitz generator, at least on my computers.

|edit| Accidentally wrote mtRandRaw() in this post -- it's mtRawRand().