From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII X-Google-Thread: 103376,e44577c74a66122 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-12-22 12:57:23 PST Newsgroups: comp.lang.ada Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!lnsnews.lns.cornell.edu!newsstand.cit.cornell.edu!news.stealth.net!news.stealth.net!newshosting.com!news-xfer1.atl.newshosting.com!uunet!dca.uu.net!ash.uu.net!world!news From: Robert A Duff Subject: Re: what's wrong with random User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Sender: news@world.std.com (Mr Usenet Himself) Message-ID: Date: Sun, 22 Dec 2002 20:56:31 GMT Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=iso-8859-1 References: <3e05fbdf.4089296@news.freenet.de> <3e060eb9.4328921@news.freenet.de> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Organization: The World Public Access UNIX, Brookline, MA Xref: archiver1.google.com comp.lang.ada:32207 Date: 2002-12-22T20:56:31+00:00 List-Id: see@messagebody.com (Jan) writes: > On Sun, 22 Dec 2002 18:38:33 GMT, Robert A Duff > 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? This is what I mean: 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); G : My_Random.Generator; function Generate_FileName (Length : Positive) return String is I : Int_Slice; Result : String (1 .. Length); begin for X in 1..Length loop I := My_Random.Random(G); Result(X) := valid_chars(I); end loop; return Result; end Generate_FileName; begin My_Random.Reset(G); for X in 1..10 loop Put_Line(Generate_Filename(8)); end loop; end Random_Test;