From: see@messagebody.com (Jan)
Subject: Re: what's wrong with random
Date: Sun, 22 Dec 2002 19:17:25 GMT
Date: 2002-12-22T19:17:25+00:00 [thread overview]
Message-ID: <3e060eb9.4328921@news.freenet.de> (raw)
In-Reply-To: wccr8c9ew5y.fsf@shell01.TheWorld.com
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1375 bytes --]
On Sun, 22 Dec 2002 18:38:33 GMT, Robert A Duff
<bobduff@shell01.TheWorld.com> wrote:
>I think you want the generator to be global to Generate_FileName.
>Otherwise, it will be reinitialized each time Generate_FileName
>is called.
>
>- Bob
What do you mean? Can you give an example?
Here is a working version:
--------
with Ada.Text_IO, Ada.Numerics.Discrete_Random;
use Ada.Text_IO;
procedure Random_Test is
valid_chars : String :=
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
& "0123456789!�$%&()=@+-;_#";
subtype Int_Slice is Integer range valid_chars'range;
package My_Random is new Ada.Numerics.Discrete_Random (Int_Slice);
function Generate_FileName (Length : Positive) return String is
G : My_Random.Generator;
I : Int_Slice;
Result : String (1 .. Length);
begin
My_Random.Reset(G);
for X in 1..Length
loop
I := My_Random.Random(G);
Result(X) := valid_chars(I);
end loop;
return Result;
end Generate_FileName;
begin
for X in 1..10
loop
Put_Line(Generate_Filename(8));
end loop;
end Random_Test;
---------------
When I put
subtype Int_Slice is Integer range valid_chars'range;
package My_Random is new Ada.Numerics.Discrete_Random (Int_Slice);
into the function, nothing changes.
Thanks.
next prev parent reply other threads:[~2002-12-22 19:17 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-12-22 18:03 what's wrong with random Jan
2002-12-22 18:38 ` Robert A Duff
2002-12-22 19:17 ` Jan [this message]
2002-12-22 20:23 ` tmoran
2002-12-22 20:56 ` Robert A Duff
2002-12-23 16:39 ` Jan
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox