🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.delphi.language.objectpascal
Article #193

Re: Randomize and Random

#193
From: Martin Strand
Date: Mon, 26 Jan 2004 14:08
37 lines
1863 bytes
Sven Pran wrote:

> "Eugene V. Goldberg" <egold@mts-nn.ru> wrote in message

>> function TfrmTickets.GetPassword: String;
>> var
>>   i, Digit: Integer;
>> begin
>>   Randomize;
>>   Result := '';
>>   for i := 1 to 8 do
>>   begin
>>     Digit := Random(10);
>>     if Digit = 0 then
>>       Digit := 1;
>>     Result := Result + IntToStr(Digit)
>>   end;
>> end;

> Digit := Random(10) generates a single number (digit) in the range
> 0..9 and then you change every occurrence of the digit 0 to digit 1
>
> This results is no zero digits and twice the count of number one
> digits to what I assume you want (equal probability for each digit in
> the range)?

... so a better solution would be
  Digit := Random(Highest-1)+1;
In this case, your numbers will be in the range 1..Highest.

-- 
mvh
Martin Strand

-- 
I didn't intend to do a thing today
and so far I'm right on schedule!
Technical Details
Message-ID: <40151efd@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <4014fbf5@newsgroups.borland.com> <401501e6@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 109d30,64bfe8b17e3a4cc8
X-Google-Attributes: gid109d30,public
X-Google-ArrivalTime: 2004-01-26 06:10:29 PST
From: "Martin Strand" <marstr2(RemoveThis)@online.no>
Newsgroups: borland.public.delphi.language.objectpascal
References: <4014fbf5@newsgroups.borland.com> <401501e6@newsgroups.borland.com>
Subject: Re: Randomize and Random
Date: Mon, 26 Jan 2004 15:08:08 +0100
Lines: 39
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
NNTP-Posting-Host: 130.67.209.52
Message-ID: <40151efd@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1075126013 130.67.209.52 (26 Jan 2004 06:06:53 -0700)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail