Und eine Compiler unabhängige version (aus C hilfe genommen):
Zitat:
static unsigned long int next = 1;
int myrand(void) /* RAND_MAX assumed to be 32767 */
{
next = next * 1103515245 + 12345;
return((unsigned int)(next/65536) % 32768);
}
void mysrand(unsigned int seed)
{
next = seed;
}
In Delphi:
Delphi-Quellcode:
var next:cardinal = 1;
function myrand():cardinal /* RAND_MAX assumed to be 32767 */
begin
next := next * 1103515245 + 12345;
Result := cardinal( (next div 65536) mod 32768);
end;
procedure mysrand(seed : cardinal)
begin
next := seed;
end;