home *** CD-ROM | disk | FTP | other *** search
- Path: informatik.tu-muenchen.de!fischerj
- From: fischerj@informatik.tu-muenchen.de (Juergen "Rally" Fischer)
- Newsgroups: comp.sys.amiga.programmer
- Subject: Re: Random Number Generation
- Date: 29 Feb 1996 13:12:12 GMT
- Organization: Technische Universitaet Muenchen, Germany
- Distribution: world
- Message-ID: <4h48nc$jpu@sunsystem5.informatik.tu-muenchen.de>
- References: <199602071623.QAA00075@sable.ox.ac.uk> <Pine.OSF.3.91.960207175121.20357B-100000@hai.hiMolde.no> <19960207.41F660.11A72@aj050.du.pipex.com> <1100.6613T1273T666@himolde.no> <692.6619T1254T1752@in.net> <4g2bi9$1fls@rs18.hrz.th-darmstadt.de> <19960220.7D62838.7EC3@mojaveg.ridgecrest.ca.us> <2108.6624T1432T2901@cs.ruu.nl>
- NNTP-Posting-Host: hphalle2i.informatik.tu-muenchen.de
- Originator: fischerj@hphalle2i.informatik.tu-muenchen.de
-
-
- In article <2108.6624T1432T2901@cs.ruu.nl>, wsldanke@cs.ruu.nl (Wessel Dankers) writes:
- |> >> #include <stdlib.h>
- |> >> ....
- |> >> num = ( (float) rand() / 32767E0 ) * ( high - low ) + low;
- |>
- |> >In theory, this is a very good suggestion. In practice, rand() is a
- |> >very poor RNG. Run any common statistical tests on rand()'s output
- |> >to see.
- |>
- |> What's wrong with FastRand()?
- |>
- |> From a totally unexpected corner I got this article, which, amongst a lot of
- |> stuff about why god doesn't exist, contained the following algorithm as an
- |> *example*, so I don't know how good it is. (layout slightly changed by me).
-
- AFAIK very good. I have tested such a "shift and eor" years ago, and
- it was good enough to generate .... what's the word for the thing a
- TV does if there's no channel ? :)
- Well, the function does it both for gfx and sound.
-
- float. naaaaah.
-
- |>
- |> --
- |> From: PAGAN <pagan@delphi.com>
- |> Subject: Re: Atheism; the perfect antidote to poetry and style.
- |> Date: Sat, 10 Feb 96 04:15:01
- |> Newsgroups: alt.atheism.moderated
- |>
- |> /*********************************************************************
- |> RANDOM number generator
- |> returns a random number from one to the value passed
- |> repeat rate OTO 1e6
- |> *********************************************************************/
- |> int random(int val)
- |> { int num; /* this is what will be returned */
- |> int bit0, bit1, bit14;
- |> static int rndval=2; /* seed value */
- |>
- |> if(val<0) /* if a negative value passed */
- |> rndval=-val; /* reseed */
- |>
- |> bit0 = rndval & 1;
- |> bit1 = (rndval & 2) >> 1;
- |> bit14 = bit0 ^ bit1;
- |> rndval >>= 1;
- |> rndval |= bit14 << 14;
- |>
- |> num = rndval % val;
-
- huh ? a div ? I sugesst to get it run without div.
-
- |> return num ? num : val;
- |> }
- |>
- |> /*********************************************************************
- |> SEED the RANDOM number generator
- |> random number seed for the above
- |> *********************************************************************/
- |> seedrandom() /* negative value to seed the generator */
- |> { random(-systemticks()); /* seed with system tick count */
- |> }
- |> --
- |>
- |>
- |> --
- |> Wessel Dankers _\\|//_ <wsldanke@cs.ruu.nl>
- |> ///|\\\
- |> ----------------------------oOO--(_)---OOo----------------------------
- |> `Never imagine yourself not to be otherwise than what it might appear
- |> to others that what you were or might have been was not otherwise than
- |> what you had been would have appeared to them to be otherwise.'
- |>
-