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,FREEMAIL_FROM, 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: johnherro@aol.com (John Herro) Subject: Re: Random Number problems Date: 1997/10/01 Message-ID: <19971001143301.KAA07525@ladder01.news.aol.com>#1/1 X-Deja-AN: 277042213 X-Admin: news@aol.com Organization: AOL http://www.aol.com Newsgroups: comp.lang.ada Date: 1997-10-01T00:00:00+00:00 List-Id: David Muhammad writes: > I have written the Random Number Generator > function but how do I tell the compiler to > select a number between 1and 52? It depends on what your function Rand_Num returns. Suppose Rand_Num returns a Float between 0.0 and 1.0. Then the following should work in both Ada 95 and Ada 83. If you have "subtype Pseudorand is Integer range 1 .. 52;" and you declare "P : Pseudorand;", you could write P := Pseudorand(Rand_Num*52.0 + 0.5); The expression within the parentheses is a Float. When Ada converts a Float to an integer type, it rounds. That's why I added 0.5 and not 1.0. If Rand_Num is just above 0.0, P will be 1, and if Rand_Num is just below 1.0, P will be 52. With some Ada compilers, it's not certain which way it will round if the fractional part of the Float is exactly 0.5. So if your Rand_Num function might return exactly 0.0 or 1.0, you may have to add code to check that the result of rounding is between 1 and 52 before storing in P. (E.g., if the result is 0, force it to 1 before storing, and force a result of 53 to 52.) I hope this helps. - John Herro Download the shareware Ada Tutor program at http://members.aol.com/AdaTutor ftp://members.aol.com/AdaTutor