|
On Mon, 18 Jun 2001, Jim Langston wrote: > According to the documentation, rand returns a number from 0 to RAND_MAX, > and I'm not sure what RAND_MAX is defined as, most likely 32767, 65535, > or some other such number. With rand it has always been necessary to > do some math calculations to return the number you want. I *think* you can do: #define RAND_MAX <some upper bound> and change RAND_MAX for your application. If you are thinking about writing your own function to handle this stuff take at look at the source code to the "random" program on a Slackware linux distribution. This handy little program can take as an argument an upper bound and return a random number between 0 and (upper bound - 1). Of course you shouldn't copy any of the code into your function unless you plan on publishing it under the GPL (unless you don't plan on ever distributing your work either). <off topic side note> I just used the random program at home in a bash script to choose mp3's at random and play them from cron. Pretty good alarm clock :) </off topic side note> James Rich james@eaerich.com +--- | This is the RPG/400 Mailing List! | To submit a new message, send your mail to RPG400-L@midrange.com. | To subscribe to this list send email to RPG400-L-SUB@midrange.com. | To unsubscribe from this list send email to RPG400-L-UNSUB@midrange.com. | Questions should be directed to the list owner/operator: david@midrange.com +---
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.