Re: rand() pattern in texture?

From: Mensanator (mensanator_at_aol.compost)
Date: 10/10/04


Date: 10 Oct 2004 15:44:49 GMT


>Subject: rand() pattern in texture?
>From: "codemagic" codemagic@gmail.com
>Date: 10/10/2004 8:24 AM Central Standard Time
>Message-id: <1097414643.721516.69860@f14g2000cwb.googlegroups.com>
>
>
>Hi,
>
>I am generating a texture of 1024 * 1024 pixels. I am using rand() % c
>to prefill it with some noise before adding some fractal noise.
>However, perhaps ten percent of the time I am seeing line anomalies in
>the prefilled texture.
>
>Do you think this is due to repetition in the sequence?

Or at least repetion in the portion of the random number that sets the pixel.
A random number's least significant bits are less reliable than the most
significant bits.

?Why can I only
>spot the pattern occasionally? Somebody suggested that not all seeds
>are equal - is that true? I srand on timeGetTime().

The random number generator has a certain period after which it repeats.
All a seed does is reposition your starting point within the period. If a
certain
area of the period gives you the line anomoly, then there are a million seeds
that will include that anomoly. If the period is larger than a million, than
there
will be seeds that don't include it (although they may show a different
anomoly).

>
>Can someone recommend a decent alternative implementation?

Lookup Mersenne Twister. The delelopers of the Python language didn't like
their original random number generator either and changed it to an
implementaion
of Mersenne Twister. Here's what the manual says about it:

<quote>
Python uses the Mersenne Twister as the core generator. It produces 53-bit
precision floats and has a period of 2**19937-1. The underlying implementation
in C is both fast and threadsafe. The Mersenne Twister is one of the most
extensively tested random number generators in existence. However, being
completely deterministic, it is not suitable for all purposes, and is
completely
unsuitable for cryptographic purposes.
</quote>

Do a Google search, you'll find C source code available. I know because I've
got a copy of it (but don't recall where I got it from). If you can't find it,
write back.

>Needs to be no slower.

Is a fast random number generator worth it if it produces crappy results?
Perl seems to be much faster than Python but Perl fails the DieHard test
whereas Python does not.

>
>Thanks a lot!
>
>Tom

-- 
Mensanator
Ace of Clubs


Relevant Pages

  • Re: rand() pattern in texture?
    ... >The random number generator has a certain period after which it repeats. ... >Lookup Mersenne Twister. ... >Python uses the Mersenne Twister as the core generator. ... >Perl seems to be much faster than Python but Perl fails the DieHard test ...
    (sci.math)
  • Re: What have we learned..? Re: How fast can you cheat..?
    ... The protocol involving the Mersenne Twister would be as follows. ... your opponent would switch to a completely ... your opponent would send you the seeds so that you could verify that the ... using some other generator, say Blum-Blum-Shub. ...
    (rec.games.backgammon)
  • Re: Random number generation IP Sharp APL?
    ... The built in random number generator in every APL implementation that I have ... In general, in a linear congruential sequence, the next member of the sequence ... Usually this is done by choosing the modulus first, ... You achieve this by picking four seeds that are far ...
    (comp.lang.apl)
  • Re: Random Seeding
    ... provided by it's inventors allows for longer seeds. ... used to perturb the deterministic generator now and then. ... D.H. Lehmer used something very like this ... Since this multiplier ...
    (comp.lang.c)
  • Re: Math.random
    ... I would definitely set 2 much higher, since there are many PRNGs available ... My suggestion is to replace Lehmer, e.g., by Marsaglia's KISS32. ... UUID generator, to which this discussion is related - but apparently ...
    (comp.lang.javascript)