63/64 bit version of Delphi's function random( aRange : integer ) : integer; ?
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


sci.crypt archive

63/64 bit version of Delphi's function random( aRange : integer ) : integer; ?

From: Dr John Stockton <jrs@merlyn.demon.co.uk>
Date: Sat Apr 29 2006 - 00:15:42 CEST

JRS: In article <4451913f$0$501$61c65585@uq-127creek-reader-03.brisbane
.pipenetworks.com.au>, dated Fri, 28 Apr 2006 13:51:17 remote, seen in
news:alt.comp.lang.borland-delphi, Mike Warren <miwa-not-this-bit@or-
this-csas.net.au> posted :
>Skybuck Flying wrote:
>> Delphi has a random function which looks like follows:
>>
>> function Random( aRange : integer ) : integer;
>>
>> The problem for me is that it only returns 32 bits... actually just
>> 31 bits.
>> Delphi has no unsigned 64 bit integer... so a signed 63 bit integer
>> for now will have to do...
>
>Can't you just use this?
>
>var
> I: Int64;
>
>I := Random($FFFFFFFF) * $100000000 + Random($FFFFFFFF);

Random(N), IIRC, produces in the range 0 to N-1. Therefore, ISTM, your
method omits those numbers where either DWORD is $FFFFFFFF.

There's no need to go to the expense of * and + if the components are
assigned directly to the upper and lower halves of the QWORD; and
Pascal/Delphi can do that in various ways.

That also eliminates some range/overflow checking, which saves time and
(possibly) false warnings.

SF is kill-ruled here.
 

-- 
 © John Stockton, Surrey, UK.  ?@merlyn.demon.co.uk   Delphi 3   Turnpike 4 ©
 <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/&c., FAQqy topics & links;
 <URL:http://www.bancoems.com/CompLangPascalDelphiMisc-MiniFAQ.htm> clpdmFAQ;
 <URL:http://www.borland.com/newsgroups/guide.html> news:borland.* Guidelines
Received on Mon May 1 02:05:52 2006