This should do the thing:
Edited second Random2() result type.Code:function Random2(const seed, offset: cardinal): double; overload; var oldSeed: cardinal; begin oldSeed:=randseed; // Save old seed randseed:=seed+offset; // Shouldn't need to check high(cardinal) ranges. // Overflowing should still do the math perfectly. result:=random(); randseed:=oldSeed; // Restore it afterwards, // So that use of normal Random() outside of this function is not interrupted. end; function Random2(const n: cardinal; const seed, offset: cardinal): cardinal; overload; begin result:=trunc(Random2(seed, offset)*n); end;
Bookmarks