× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.


  • Subject: Re: Controlling ('rand') random number upper limit
  • From: Chris Rehm <javadisciple@xxxxxxxxxxxxx>
  • Date: Tue, 19 Jun 2001 09:13:38 -0700
  • User-Agent: Mozilla/5.0 (Windows; U; Win98; en-US; m18) Gecko/20010131 Netscape6/6.01

     His message did show that he was using 32768 as the divisor. So, 
he'll get a value between 0/32768 and 32767/32768.
   This gives me a chance to use the only thing I've ever liked about 
Windows, the calculator it comes with. So he'll get a value ranging from 
0 to .999969482421875 (barring any typos on my part).
   That should give as flat a distribution across his own range as the 
generator has across its own range, provided he does not wish to 
generate numbers larger than 32767. If he does, he will need a different 
random number generator or to append multiple results from this 
generator bitwise and then divide by the new range.

Jim Langston wrote:

> Chris, Paul,
> 
> That being said, Paul's solution can still be screwed, depending
> on how the system is adjusting for math.  One out of 32767 times
> it will return a value 1 greater than his range.
> 
> For a range 1 to 10 (normal return):
> 32766 / 32767 = 0.999969481 * 10 = 9.99969481.  Truncate returns

[snip] s/b 32766/32768

> Regards,
> 
> Jim Langston
> 
-- 

   Chris Rehm
<mailto:javadisciple@earthlink.net>



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 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.