TIP: Click on subject to list as thread! ANSI
echo: nthelp
to: Robert Comer
from: Geo
date: 2004-12-09 22:16:00
subject: Re: c++ help

From: "Geo" 

Are you sure it's not just stored as an int? I mean if it's integer math
then how would it handle this

int n = (rand()/32767)*9999999999999

That shouldn't generate a cpu error, the error would come when it goes to
store a multibyte value in a single byte location (or maybe at compile
time?)

Geo.

"Robert Comer"  wrote in message
news:41b84153$1{at}w3.nls.net...
> > Why would it return 0? Do I need another set of () around the whole
thing?
>
> That whole expression is calculated as int's...
>
> - Bob Comer
>
>
> "Geo"  wrote in message
news:41b82ee0$1{at}w3.nls.net...
> > Why would it return 0? Do I need another set of () around the whole
thing?
> >
> > I see what you are saying about the bias if you use a straight rand()
> > function but when you divide by RAND_MAX then rand() gives a value
between
> > 0
> > and 1 which should have an even distribution, no?
> >
> > int n = (rand()/32767)*9999
> >
> > should give you an even distribution of numbers from 1 to 9999. I guess
I
> > could write a program that loops and tracks the distribution to see,
> > something fun to play with this weekend.
> >
> > Geo.
> >
> > "Paul Ranson"  wrote in message
> > news:41b5b7cb{at}w3.nls.net...
> >> That won't fix it, and in fact, will generally return 0...
> >>
> >> If 'rand' is well designed then a series of calls of it should return a
> >> series of numbers between 0 and RAND_MAX (32767 usually) where each
> >> number
> >> occurs with the same frequency, given a long enough series. Obviously
for
> >> any given seed you get the same series each time you call srand. This
> > isn't
> >> bias, it's pseudo.
> >>
> >> If you disregard any return from rand between 32760 and 32767 then I
> >> think
> >> your distribution of 0-9 will be even. Happy to be proven wrong on
> >> this...
> >>
> >> Paul
> >>
> >> "Geo."  wrote in message
news:41b5aede$1{at}w3.nls.net...
> >> > well a simple solution to that would be
> >> >
> >> > int n = (rand()/RAND_MAX)*99999
> >> >
> >> > That should give me a pretty random distribution of the
right most 4
> >> > characters, theoretically with no bias.
> >> >
> >> > Geo.(there actually is a bias dependent on the time you run the
> >> > program)
> >> >
> >>
> >>
> >
> >
>
>

--- BBBS/NT v4.01 Flag-5
* Origin: Barktopia BBS Site http://HarborWebs.com:8081 (1:379/45)
SEEN-BY: 633/267 270 5030/786
@PATH: 379/45 1 396/45 106/2000 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.