Re: Simple Random Number Generator/Function
From: Hugo Pfoertner (nothing_at_abouthugo.de)
Date: 03/08/05
- Next message: robert j. kolker: "Re: Epistemology 201: The Science of Science"
- Previous message: Jason: "Re: Possible proof of Gabriel's Theorem?"
- In reply to: indras_at_efn.org: "Re: Simple Random Number Generator/Function"
- Next in thread: indras_at_efn.org: "Re: Simple Random Number Generator/Function"
- Reply: indras_at_efn.org: "Re: Simple Random Number Generator/Function"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 08 Mar 2005 22:48:31 +0100
indras@efn.org schrieb:
>
> C, Pascal, or any languages that are easy to read will be fine. This
> generator will be used in DVD Authoring. There is a rand function in
> DVD specification, but few DVD players do not like them, that's why I
> would like to create one.
The Standard C generator from
Brian W Kernighan and Dennis M. Ritchie, The C Programming Language
(Second Edition) Prentice Hall Software Series, 1988
uses x(1)=1, x(n)=(1103515245 * x(n-1) + 12345) mod 2^31
a(n)=floor(x(n)/2^16)
C Program: static unsigned int next = 1; int rand( ) { next = next *
1103515245 + 12345; return ((next >>16) & 32767); }
If you want different behavior for different runs, you have to replace
"next=1" by something taking a variable input (e.g. clock). C provides
the function srand ( ... ); for this pupose.
Hugo
- Next message: robert j. kolker: "Re: Epistemology 201: The Science of Science"
- Previous message: Jason: "Re: Possible proof of Gabriel's Theorem?"
- In reply to: indras_at_efn.org: "Re: Simple Random Number Generator/Function"
- Next in thread: indras_at_efn.org: "Re: Simple Random Number Generator/Function"
- Reply: indras_at_efn.org: "Re: Simple Random Number Generator/Function"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|