Article View: borland.public.delphi.language.objectpascal
Article #182Re: Randomize and Random
From: Sven Pran
Date: Mon, 26 Jan 2004 12:02
Date: Mon, 26 Jan 2004 12:02
56 lines
2469 bytes
2469 bytes
Others have already correctly commented your abuse of "Randomize", but there is another "feature" in your code which I believe is undesired: 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)? regards Sven "Eugene V. Goldberg" <egold@mts-nn.ru> wrote in message news:4014fbf5@newsgroups.borland.com... > I have the following functions: > > function TfrmTickets.GetLogin(Prefix: String): String; > var > i, Digit: Integer; > begin > Result := Prefix; > Randomize; > for i := Length(Result) + 1 to 8 do > begin > Digit := Random(10); > if Digit = 0 then > Digit := 1; > Result := Result + IntToStr(Digit) > end; > end; > > 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; > > I am calling this functions one after another in a loop, 10 times. > And as the result i have login = password = somestring1 for 4 calls, > login = password = somestring2 for other 6 calls. So i have the same > strings generated several times. Whats wrong? > > I need to generate different values for login and password every time. > > Thanx, > Eugene. > >
Technical Details
Message-ID:
<401501e6@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-mailReferences:
<4014fbf5@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 04:09:38 PST From: "Sven Pran" <no.direct@mail.please> Newsgroups: borland.public.delphi.language.objectpascal References: <4014fbf5@newsgroups.borland.com> Subject: Re: Randomize and Random Date: Mon, 26 Jan 2004 13:02:46 +0100 Lines: 58 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.1106 NNTP-Posting-Host: 83.108.10.156 Message-ID: <401501e6@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1075118566 83.108.10.156 (26 Jan 2004 04:02:46 -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