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-7-bit X-Google-Thread: 103376,c7fc42d2c6a0eedc X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-04-03 19:50:44 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!arclight.uoregon.edu!wn13feed!worldnet.att.net!204.127.198.203!attbi_feed3!attbi.com!sccrnsc02.POSTED!not-for-mail From: "Steve" Newsgroups: comp.lang.ada References: Subject: Re: Ada2005 random X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 Message-ID: NNTP-Posting-Host: 12.211.13.75 X-Complaints-To: abuse@attbi.com X-Trace: sccrnsc02 1049428230 12.211.13.75 (Fri, 04 Apr 2003 03:50:30 GMT) NNTP-Posting-Date: Fri, 04 Apr 2003 03:50:30 GMT Organization: AT&T Broadband Date: Fri, 04 Apr 2003 03:50:30 GMT Xref: archiver1.google.com comp.lang.ada:35911 Date: 2003-04-04T03:50:30+00:00 List-Id: The following code almost does what you asked for. The problem is that without the delays the selected random number is always the same. I think this is because a new generator is created for each call, and the "seed" value (based on time) is the same unless I include delays. with Ada.Integer_text_Io; with Ada.Text_Io; procedure CLA_Test2 is function Check( low, high : Integer ) return Integer is subtype check_range is integer range low .. high; package ranged_random is new Ada.Numerics.Discrete_Random( check_range ); gen : ranged_random.Generator; begin ranged_random.reset( gen ); return ranged_random.Random( gen ); end Check; begin Ada.Integer_Text_Io.Put( Check( 1, 10 ) ); Ada.Text_Io.New_Line; Delay 1.0; Ada.Integer_Text_Io.Put( Check( 1, 10 ) ); Ada.Text_Io.New_Line; Delay 1.0; Ada.Integer_Text_Io.Put( Check( 1, 10 ) ); Ada.Text_Io.New_Line; Delay 1.0; Ada.Integer_Text_Io.Put( Check( 1, 10 ) ); Ada.Text_Io.New_Line; Delay 1.0; end CLA_Test2; I would probably go with creating my own routine using the float package. Steve (The Duck) "Peter Hermann" wrote in message news:b6eog4$8jl$1@news.uni-stuttgart.de... > In an application I need a variable discrete random function. > > Due to good reason I am reluctant to use my own very old > http://www.csv.ica.uni-stuttgart.de/ftp/pub/ada/ica/misc/randomph.txt > > Instead, I would prefer to use > generic > type Result_Subtype is (<>); > package Ada.Numerics.Discrete_Random is > > which offers a > function Random (Gen : Generator) return Result_Subtype; > > but does not offer something like > function Random (Gen : Generator; > from : Result_Subtype := Result_Subtype'first; > to : Result_Subtype := Result_Subtype'last) > return Result_Subtype; > which may or may not make sense in that raw disguise. > > Anyway in Ada95, I have to roll my own code or let me send one ;-) > > Does an AI exist for Ada95 or Ada2005? > Did I miss something? > > -- > --Peter Hermann(49)0711-685-3611 fax3758 ica2ph@csv.ica.uni-stuttgart.de > --Pfaffenwaldring 27 Raum 114, D-70569 Stuttgart Uni Computeranwendungen > --http://www.csv.ica.uni-stuttgart.de/homes/ph/ > --Team Ada: "C'mon people let the world begin" (Paul McCartney)