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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,6bc361dc425f4265 X-Google-Attributes: gid103376,public From: mcc@tyrolia.cs.princeton.edu (Martin C. Carlisle) Subject: Re: Random Number problems Date: 1997/10/01 Message-ID: <60tsk9$5gg$1@cnn.Princeton.EDU>#1/1 X-Deja-AN: 278854695 References: <60q1hm$8oq$1@goanna.cs.rmit.edu.au> <3431B598.41C6@activist.com> Organization: US Air Force Academy, Dept of Computer Science Newsgroups: comp.lang.ada Date: 1997-10-01T00:00:00+00:00 List-Id: In article <3431B598.41C6@activist.com>, David Muhammad wrote: >>I am trying to write a function that will > use a Random Number Generator and then return a random value between >1 and 52. I have written the Random Number Generator function but how >do I tell the compiler to select a number between 1 and 52. > >a) declare a subtype > subtype pseudorand is range 1..52 >b) Call my randomnumber from function Rand_Num >c) NOw somehow convert some "Number" to a range between 1 and 52. >I am stuck ?? Most people would instead use the very nice built-in random number generator. E.g. package my_random is new Ada.Numerics.Discrete_Random(pseudorand); g : my_random.generator; x : pseudorand; begin my_random.reset(g); x := my_random.random(g); For more info, see LRM A.5.2, Barnes p. 54, Feldman pp 320-322, Cohen p. 93 If you insist on using your own, you want to use mod. --Martin -- Martin C. Carlisle, Computer Science, US Air Force Academy mcc@cs.usafa.af.mil, http://www.usafa.af.mil/dfcs/bios/carlisle.html DISCLAIMER: This content in no way reflects the opinions, standard or policy of the US Air Force Academy or the United States Government.