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


Groups > comp.lang.c > #93380

Re: Learn "elusive" and "reprimand" using C!

From Keith Thompson <kst-u@mib.org>
Newsgroups comp.lang.c
Subject Re: Learn "elusive" and "reprimand" using C!
Date 2016-09-11 13:58 -0700
Organization None to speak of
Message-ID <lneg4q6tm6.fsf@kst-u.example.com> (permalink)
References <elusive-20160909182549@ram.dialup.fu-berlin.de> <lnzing7u2r.fsf@kst-u.example.com> <05dd7501-f8d9-4e40-9876-8b8c7e72df98@googlegroups.com>

Show all headers | View raw


Paul N <gw7rib@aol.com> writes:
> On Friday, September 9, 2016 at 7:21:37 PM UTC+1, Keith Thompson wrote:
>> If the implementation of srand() and rand() works well, then calling
>> srand(time(0)) once, then calling rand() once for each random number
>> you need, should be sufficient.  If it doesn't work well, then no
>> amount of tweaking is going to squeeze high-quality pseudo-random
>> numbers out of it.
>
> Imagine a system where rand() returns n+1, where n is the number
> returned last time. The programmer thinks this looks a bit too
> predictable, so by suitably wrapping the function he gets a function
> that returns 2147001325 * n + 718136305 modulo 2^32. Would this
> contradict your last sentence?

Not significantly.  No real-world implementation of rand() is
*that* bad -- and your wrapped function still isn't what I'd call
high-quality.  And I'm not sure I'd call that "tweaking".

(Some rand() implementations are quite bad, though.  For example,
in the NetBSD implementation the low-order bit alternates between 0
and 1, and in general the N low-order bits repeat in a cycle of 2**N
iterations. -- unless NetBSD has fixed this since I last checked.)

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

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


Thread

Re: Learn "elusive" and "reprimand" using C! Keith Thompson <kst-u@mib.org> - 2016-09-09 12:26 -0700
  Re: Learn "elusive" and "reprimand" using C! Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-09-09 13:55 -0700
    Re: Learn "elusive" and "reprimand" using C! Richard Heathfield <rjh@cpax.org.uk> - 2016-09-09 22:04 +0100
    Re: Learn "elusive" and "reprimand" using C! Keith Thompson <kst-u@mib.org> - 2016-09-09 15:26 -0700
      Re: Learn "elusive" and "reprimand" using C! Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-09-09 14:31 -0700
        Re: Learn "elusive" and "reprimand" using C! Keith Thompson <kst-u@mib.org> - 2016-09-09 17:02 -0700
        Re: Learn "elusive" and "reprimand" using C! gazelle@shell.xmission.com (Kenny McCormack) - 2016-09-09 22:55 +0000
        Re: Learn "elusive" and "reprimand" using C! jameskuyper@verizon.net - 2016-09-09 17:01 -0700
  Re: Learn "elusive" and "reprimand" using C! Paul N <gw7rib@aol.com> - 2016-09-11 08:26 -0700
    Re: Learn "elusive" and "reprimand" using C! "James R. Kuyper" <jameskuyper@verizon.net> - 2016-09-11 11:49 -0400
    Re: Learn "elusive" and "reprimand" using C! Tim Rentsch <txr@alumni.caltech.edu> - 2016-09-11 11:51 -0700
    Re: Learn "elusive" and "reprimand" using C! Keith Thompson <kst-u@mib.org> - 2016-09-11 13:58 -0700
    Re: Learn "elusive" and "reprimand" using C! David Brown <david.brown@hesbynett.no> - 2016-09-12 09:08 +0200

csiph-web