Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #21565

Re: useful macros

From "BartC" <bc@freeuk.com>
Newsgroups comp.lang.c
Subject Re: useful macros
Date 2012-05-31 00:45 +0100
Organization A noiseless patient Spider
Message-ID <jq6bft$116$1@dont-email.me> (permalink)
References (2 earlier) <9461b5b5-79b4-422c-a50c-1b2915629009@googlegroups.com> <0.bd19cf1c61d059f4f743.20120530164534BST.87ipfdbrkx.fsf@bsb.me.uk> <4FC65479.7060004@verizon.net> <jq66o5$1gc$1@dont-email.me> <4FC6A57D.5050504@verizon.net>

Show all headers | View raw


"James Kuyper" <jameskuyper@verizon.net> wrote in message
news:4FC6A57D.5050504@verizon.net...
> On 05/30/2012 06:24 PM, BartC wrote:

>> By choosing the range 0 to 999999 for example, then dividing the result
>> by
>> 1000000.0, that ought to produce a linear distribution over 0.000000 to
>> 0.999999. That definition seems quite adequate for many purposes. I don't
>> know whether you're thinking that there are more numbers between 0.25 and
>> 0.5, than between 0.5 and 1.0 for example, and this somehow needs to be
>> reflected in this distribution.

(Between 0.25/0.5 and 0.5/1.0 probably the same; I meant within two equal
intervals.)

> More important for many purposes is the fact that you can generate only
> RAND_MAX different floating point values that way. That can be quite
> acceptable for many purposes, and completely unacceptable for others.

Minor problem. I actually use two successive calls to rand() to give me a
bigger range. And for more serious purposes, a better RNG can be plugged in
(G. Marsaglia has posted a few complicated ones here).

> Between each consecutive pair of values that can be generated there's a
> gap containing huge numbers of representable floating point values that
> can never be generated. The gaps all have exactly the same size and are
> all in phase with each other, which means they can have very noticeable
> effects on certain kinds of numerical simulations, particularly in
> Fourier analysis.

People seem to take random numbers very seriously when the subject comes up.
If it's that critical (or money is at stake), then someone would use a
specialist function or take time to put something together just right. They
wouldn't trust a throwaway macro to do the job.

(I used to do 'wallpaper' tests with early random number generators of my
own. The more interesting the patterns that were generated, the less use
they were for producing random numbers. Yet even then, they could be
surprisingly useful. Sometimes, RNGs just don't need to be that good.)

-- 
Bartc 

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

useful macros Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-05-26 13:08 -0700
  Re: useful macros winndy <jiaoyk@gmail.com> - 2012-05-29 20:26 -0700
    Re: useful macros Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-05-30 00:47 -0700
      Re: useful macros Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-05-30 16:45 +0100
        Re: useful macros James Kuyper <jameskuyper@verizon.net> - 2012-05-30 13:10 -0400
          Re: useful macros Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-05-30 21:54 +0100
          Re: useful macros "BartC" <bc@freeuk.com> - 2012-05-30 23:24 +0100
            Re: useful macros James Kuyper <jameskuyper@verizon.net> - 2012-05-30 18:55 -0400
              Re: useful macros "BartC" <bc@freeuk.com> - 2012-05-31 00:45 +0100
            Re: useful macros Keith Thompson <kst-u@mib.org> - 2012-05-30 17:53 -0700
              Re: useful macros "BartC" <bc@freeuk.com> - 2012-05-31 10:29 +0100

csiph-web