home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.pascal
- Path: sparky!uunet!utcsri!skule.ecf!torn!news.ccs.queensu.ca!mast.queensu.ca!dmurdoch
- From: dmurdoch@mast.queensu.ca (Duncan Murdoch)
- Subject: Re: Encryption and Random Numbers
- Message-ID: <dmurdoch.288.722119961@mast.queensu.ca>
- Lines: 49
- Sender: news@knot.ccs.queensu.ca (Netnews control)
- Organization: Queen's University
- References: <1992Nov17.211502.18511@lynx.dac.northeastern.edu> <dmurdoch.285.722096509@mast.queensu.ca>
- Date: Wed, 18 Nov 1992 20:52:41 GMT
-
- >In article <1992Nov17.211502.18511@lynx.dac.northeastern.edu> cschmidt@lynx.dac.northeastern.edu (Christopher Schmidt) writes:
- >>generator. It's a nice technique, except that if Borland
- >>modifies the TP random number generator, then you and your
- >>customers will be locked out of your encrypted data.
-
- I've just checked in BP 7. It appears that the Randseed update algorithm is
- the same, but the translation from Randseed to Random(N) has changed.
-
- Here's what happens now in a call to Random(N):
-
- First, Randseed is updated. The update formula is
-
- randseed := randseed*134775813 + 1;
-
- Then, treating randseed as an unsigned 32 bit quantity, Random(N) returns
-
- Random := trunc(N*randseed/2^32);
-
- The calculations inside the parentheses above must *not* be allowed to
- overflow; this makes implementation sort of tricky. One way to do it is
-
- if Randseed < 0 then
- Random := trunc(N*(randseed + 4294967296.0))/4294967296.0)
- else
- Random := trunc(N*double(randseed)/4294967296.0);
-
- I don't have the code handy to simulate the TP 6.0 Random(N) call, but it
- returns the high word of RandSeed mod N. (This may have changed between
- releases of 6.0; there were lots of complaints about the lack of uniformity
- of the distibution.)
-
- In the special case of N=256 that I used in my encryption filter, the
- difference is that TP 6 gives you the 2nd most significant byte of Randseed
- as Random(256), while BP 7 gives you the most significant byte.
-
- Finally, there's a difference between TP 6 and BP 7 in the way the
- floating point Random values are generated. BP 7 treats Randseed as a
- Longint, and returns (RandSeed+2^31)/2^32. TP 6 also treated Randseed as a
- Longint, but returned Abs(RandSeed)/2^31. (This was in $N+ mode; in $N-
- mode, TP 6 treated Randseed as unsigned, and returned RandSeed/2^32.)
-
- It appears to me both of these changes are good. There were two bugs
- listed in my TP 6 bug list about random number generation: first, the non-
- uniformity of Random(N) which has been remedied to a great extent, and
- second, the possibility that Random = 1.0, which has now been removed.
-
-
- Duncan Murdoch
- dmurdoch@mast.queensu.ca
-