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


Groups > comp.lang.c > #139043 > unrolled thread

Multi-channel rand()

Started by"Rick C. Hodgin" <rick.c.hodgin@gmail.com>
First post2018-12-24 19:54 -0500
Last post2018-12-26 11:58 -0800
Articles 20 on this page of 87 — 14 participants

Back to article view | Back to comp.lang.c


Contents

  Multi-channel rand() "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-12-24 19:54 -0500
    Re: Multi-channel rand() "Chris M. Thomasson" <invalid_chris_thomasson@invalid.invalid> - 2018-12-24 19:38 -0800
    Re: Multi-channel rand() nobody@example.org (Scott) - 2018-12-25 04:05 +0000
      Re: Multi-channel rand() "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-12-24 23:57 -0500
        Re: Multi-channel rand() Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk> - 2018-12-25 09:22 +0000
          Professional coders??? (Was: Multi-channel rand()) gazelle@shell.xmission.com (Kenny McCormack) - 2018-12-25 10:09 +0000
          Re: Multi-channel rand() "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-12-25 07:59 -0500
            Re: Multi-channel rand() Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk> - 2018-12-25 21:59 +0000
              Re: Multi-channel rand() nobody@example.org (Scott) - 2018-12-26 02:43 +0000
        Re: Multi-channel rand() rbowman <bowman@montana.com> - 2018-12-25 10:15 -0700
          Re: Multi-channel rand() Keith Thompson <kst-u@mib.org> - 2018-12-25 10:14 -0800
    Re: Multi-channel rand() Anton Shepelev <anton.txt@g{oogle}mail.com> - 2018-12-25 13:35 +0300
      Re: Multi-channel rand() fir <profesor.fir@gmail.com> - 2018-12-25 02:56 -0800
      Re: Multi-channel rand() "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-12-25 08:02 -0500
    Re: Multi-channel rand() Bart <bc@freeuk.com> - 2018-12-25 11:52 +0000
      Re: Multi-channel rand() Anton Shepelev <anton.txt@g{oogle}mail.com> - 2018-12-25 14:58 +0300
      Re: Multi-channel rand() Richard Damon <Richard@Damon-Family.org> - 2018-12-25 06:59 -0500
        Re: Multi-channel rand() "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-12-25 08:05 -0500
      Re: Multi-channel rand() "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-12-25 08:04 -0500
    Re: Multi-channel rand() Bart <bc@freeuk.com> - 2018-12-26 15:48 +0000
      Re: Multi-channel rand() "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-12-26 07:58 -0800
        Re: Multi-channel rand() Richard Damon <Richard@Damon-Family.org> - 2018-12-26 12:06 -0500
          Re: Multi-channel rand() "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-12-26 12:45 -0500
            Re: Multi-channel rand() Richard Damon <Richard@Damon-Family.org> - 2018-12-26 13:20 -0500
              Re: Multi-channel rand() "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-12-26 10:30 -0800
                Re: Multi-channel rand() "Chris M. Thomasson" <invalid_chris_thomasson@invalid.invalid> - 2018-12-26 11:35 -0800
                  Re: Multi-channel rand() "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-12-26 14:52 -0500
                Re: Multi-channel rand() Richard Damon <Richard@Damon-Family.org> - 2018-12-26 16:31 -0500
                  Re: Multi-channel rand() "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-12-26 22:28 -0500
                  Re: Multi-channel rand() "Chris M. Thomasson" <invalid_chris_thomasson@invalid.invalid> - 2018-12-30 20:42 -0800
              Re: Multi-channel rand() Keith Thompson <kst-u@mib.org> - 2018-12-26 15:32 -0800
            Re: Multi-channel rand() Bart <bc@freeuk.com> - 2018-12-26 19:38 +0000
              Re: Multi-channel rand() Keith Thompson <kst-u@mib.org> - 2018-12-26 15:35 -0800
          Re: Multi-channel rand() "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-12-26 12:59 -0500
            Re: Multi-channel rand() Richard Damon <Richard@Damon-Family.org> - 2018-12-26 16:05 -0500
          Re: Multi-channel rand() "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-12-26 13:08 -0500
            Re: Multi-channel rand() Richard Damon <Richard@Damon-Family.org> - 2018-12-26 15:50 -0500
        Re: Multi-channel rand() Bart <bc@freeuk.com> - 2018-12-26 17:42 +0000
          Re: Multi-channel rand() "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-12-26 12:48 -0500
          Re: Multi-channel rand() Richard Damon <Richard@Damon-Family.org> - 2018-12-26 12:58 -0500
            Re: Multi-channel rand() Bart <bc@freeuk.com> - 2018-12-26 19:03 +0000
              Re: Multi-channel rand() "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-12-26 14:45 -0500
                Re: Multi-channel rand() Bart <bc@freeuk.com> - 2018-12-26 20:46 +0000
                  Re: Multi-channel rand() "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-12-26 16:25 -0500
                    Re: Multi-channel rand() Richard Damon <Richard@Damon-Family.org> - 2018-12-26 17:13 -0500
                      Re: Multi-channel rand() "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-12-26 22:23 -0500
                    Re: Multi-channel rand() Bart <bc@freeuk.com> - 2018-12-26 23:39 +0000
                  Re: Multi-channel rand() Richard Damon <Richard@Damon-Family.org> - 2018-12-26 17:36 -0500
              Re: Multi-channel rand() Richard Damon <Richard@Damon-Family.org> - 2018-12-26 16:27 -0500
      Re: Multi-channel rand() rbowman <bowman@montana.com> - 2018-12-26 19:19 -0700
        Re: Multi-channel rand() Richard Damon <Richard@Damon-Family.org> - 2018-12-26 22:17 -0500
        Re: Multi-channel rand() James Kuyper <jameskuyper@alumni.caltech.edu> - 2018-12-26 19:32 -0800
        Re: Multi-channel rand() Keith Thompson <kst-u@mib.org> - 2018-12-26 19:34 -0800
          Re: Multi-channel rand() Bart <bc@freeuk.com> - 2018-12-27 11:29 +0000
            Re: Multi-channel rand() James Kuyper <jameskuyper@alumni.caltech.edu> - 2018-12-27 05:27 -0800
              Re: Multi-channel rand() "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-12-27 09:41 -0500
                Re: Multi-channel rand() "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-12-27 09:42 -0500
                  Re: Multi-channel rand() James Kuyper <jameskuyper@alumni.caltech.edu> - 2018-12-27 07:01 -0800
                    Re: Multi-channel rand() "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-12-27 10:28 -0500
                      Re: Multi-channel rand() Richard Damon <Richard@Damon-Family.org> - 2018-12-27 10:48 -0500
                        Re: Multi-channel rand() "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-12-27 11:08 -0500
                          Re: Multi-channel rand() "Chris M. Thomasson" <invalid_chris_thomasson@invalid.invalid> - 2018-12-27 13:49 -0800
                            Re: Multi-channel rand() "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-12-27 17:18 -0500
                              Re: Multi-channel rand() "Chris M. Thomasson" <invalid_chris_thomasson@invalid.invalid> - 2018-12-29 13:59 -0800
                                Re: Multi-channel rand() "Chris M. Thomasson" <invalid_chris_thomasson@invalid.invalid> - 2018-12-30 14:01 -0800
                                  Re: Multi-channel rand() Bart <bc@freeuk.com> - 2018-12-30 22:07 +0000
                                  Re: Multi-channel rand() "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-12-30 17:20 -0500
                          Re: Multi-channel rand() Richard Damon <Richard@Damon-Family.org> - 2018-12-27 17:47 -0500
                            Re: Multi-channel rand() "Chris M. Thomasson" <invalid_chris_thomasson@invalid.invalid> - 2018-12-30 20:45 -0800
                      Re: Multi-channel rand() James Kuyper <jameskuyper@alumni.caltech.edu> - 2018-12-27 08:22 -0800
                        Re: Multi-channel rand() "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-12-27 11:40 -0500
                          Re: Multi-channel rand() James Kuyper <jameskuyper@alumni.caltech.edu> - 2018-12-27 09:21 -0800
                            Re: Multi-channel rand() "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-12-27 12:45 -0500
                              Re: Multi-channel rand() James Kuyper <jameskuyper@alumni.caltech.edu> - 2018-12-27 10:57 -0800
                                Re: Multi-channel rand() "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-12-27 14:35 -0500
                                Re: Multi-channel rand() Tim Rentsch <txr@alumni.caltech.edu> - 2018-12-28 09:25 -0800
                                  Re: Multi-channel rand() Tim Rentsch <txr@alumni.caltech.edu> - 2018-12-28 09:55 -0800
                                Re: Multi-channel rand() Keith Thompson <kst-u@mib.org> - 2018-12-28 12:36 -0800
                        Re: Multi-channel rand() Robert Wessel <robertwessel2@yahoo.com> - 2018-12-27 20:34 -0600
                Re: Multi-channel rand() Richard Damon <Richard@Damon-Family.org> - 2018-12-27 10:37 -0500
              Re: Multi-channel rand() Bart <bc@freeuk.com> - 2018-12-27 14:46 +0000
                Re: Multi-channel rand() James Kuyper <jameskuyper@alumni.caltech.edu> - 2018-12-27 07:05 -0800
                  Re: Multi-channel rand() Keith Thompson <kst-u@mib.org> - 2018-12-27 11:28 -0800
                    Re: Multi-channel rand() James Kuyper <jameskuyper@alumni.caltech.edu> - 2018-12-27 12:07 -0800
                      Re: Multi-channel rand() Keith Thompson <kst-u@mib.org> - 2018-12-27 12:47 -0800
                        Re: Multi-channel rand() James Kuyper <jameskuyper@alumni.caltech.edu> - 2018-12-27 14:47 -0800
    Re: Multi-channel rand() "Chris M. Thomasson" <invalid_chris_thomasson@invalid.invalid> - 2018-12-26 11:58 -0800

Page 1 of 5  [1] 2 3 4 5  Next page →


#139043 — Multi-channel rand()

From"Rick C. Hodgin" <rick.c.hodgin@gmail.com>
Date2018-12-24 19:54 -0500
SubjectMulti-channel rand()
Message-ID<pvrv1d$4ls$1@dont-email.me>
Is there an equivalent of a multi-channel rand() function that enables
multiple simultaneous separate pseudo-random number generators by some-
thing like a handle or instance of each in the standard library?

-- 
Rick C. Hodgin

[toc] | [next] | [standalone]


#139044

From"Chris M. Thomasson" <invalid_chris_thomasson@invalid.invalid>
Date2018-12-24 19:38 -0800
Message-ID<pvs8nt$dpq$1@dont-email.me>
In reply to#139043
On 12/24/2018 4:54 PM, Rick C. Hodgin wrote:
> Is there an equivalent of a multi-channel rand() function that enables
> multiple simultaneous separate pseudo-random number generators by some-
> thing like a handle or instance of each in the standard library?
> 

Yes. This can be accomplished in standard C++. Well, not using rand(), 
but there are other ways. rand_r in POSIX?, just kidding... Completely 
independent per-thread prngs are possible with C++. Interested?

[toc] | [prev] | [next] | [standalone]


#139046

Fromnobody@example.org (Scott)
Date2018-12-25 04:05 +0000
Message-ID<5c21aac6.1374977281@news.xmission.com>
In reply to#139043
On Mon, 24 Dec 2018 19:54:29 -0500, "Rick C. Hodgin"
<rick.c.hodgin@gmail.com> wrote:

>Is there an equivalent of a multi-channel rand() function that enables
>multiple simultaneous separate pseudo-random number generators by some-
>thing like a handle or instance of each in the standard library?

Not as such AFAIK. It looks like initstate and setstate (stdlib) let
you extract and reinstate the prng context as you like, which can be
exploited to the same end.

[toc] | [prev] | [next] | [standalone]


#139050

From"Rick C. Hodgin" <rick.c.hodgin@gmail.com>
Date2018-12-24 23:57 -0500
Message-ID<pvsd8g$tlr$2@dont-email.me>
In reply to#139046
On 12/24/2018 11:05 PM, Scott wrote:
> On Mon, 24 Dec 2018 19:54:29 -0500, "Rick C. Hodgin"
> <rick.c.hodgin@gmail.com> wrote:
> 
>> Is there an equivalent of a multi-channel rand() function that enables
>> multiple simultaneous separate pseudo-random number generators by some-
>> thing like a handle or instance of each in the standard library?
> 
> Not as such AFAIK. It looks like initstate and setstate (stdlib) let
> you extract and reinstate the prng context as you like, which can be
> exploited to the same end.

Microsoft's Visual C++ comes with source code you can step into for
their rand() function.  It uses a small block of code.  I had the
idea to pull that code out and wrap it in a struct or class and then
have instances.  I think that would work, but I'm not sure if it's
legal (because it's Microsoft's code) ... so I'm looking for something
that is available for use, preferably in the public domain.

-- 
Rick C. Hodgin

[toc] | [prev] | [next] | [standalone]


#139054

FromMr Flibble <flibbleREMOVETHISBIT@i42.co.uk>
Date2018-12-25 09:22 +0000
Message-ID<YEmUD.25991$922.5644@fx06.fr7>
In reply to#139050
On 25/12/2018 04:57, Rick C. Hodgin wrote:
> On 12/24/2018 11:05 PM, Scott wrote:
>> On Mon, 24 Dec 2018 19:54:29 -0500, "Rick C. Hodgin"
>> <rick.c.hodgin@gmail.com> wrote:
>>
>>> Is there an equivalent of a multi-channel rand() function that enables
>>> multiple simultaneous separate pseudo-random number generators by some-
>>> thing like a handle or instance of each in the standard library?
>>
>> Not as such AFAIK. It looks like initstate and setstate (stdlib) let
>> you extract and reinstate the prng context as you like, which can be
>> exploited to the same end.
> 
> Microsoft's Visual C++ comes with source code you can step into for
> their rand() function.  It uses a small block of code.  I had the
> idea to pull that code out and wrap it in a struct or class and then
> have instances.  I think that would work, but I'm not sure if it's
> legal (because it's Microsoft's code) ... so I'm looking for something
> that is available for use, preferably in the public domain.

Professional coders don't use rand(); they use <random> instead.

/Flibble

-- 
“You won’t burn in hell. But be nice anyway.” – Ricky Gervais

“I see Atheists are fighting and killing each other again, over who 
doesn’t believe in any God the most. Oh, no..wait.. that never happens.” – 
Ricky Gervais

"Suppose it's all true, and you walk up to the pearly gates, and are 
confronted by God," Bryne asked on his show The Meaning of Life. "What 
will Stephen Fry say to him, her, or it?"
"I'd say, bone cancer in children? What's that about?" Fry replied.
"How dare you? How dare you create a world to which there is such misery 
that is not our fault. It's not right, it's utterly, utterly evil."
"Why should I respect a capricious, mean-minded, stupid God who creates a 
world that is so full of injustice and pain. That's what I would say."

[toc] | [prev] | [next] | [standalone]


#139055 — Professional coders??? (Was: Multi-channel rand())

Fromgazelle@shell.xmission.com (Kenny McCormack)
Date2018-12-25 10:09 +0000
SubjectProfessional coders??? (Was: Multi-channel rand())
Message-ID<pvsvlc$84n$1@news.xmission.com>
In reply to#139054
In article <YEmUD.25991$922.5644@fx06.fr7>,
Mr Flibble  <flibbleREMOVETHISBIT@i42.co.uk> wrote:
...
>Professional coders don't use rand(); they use <random> instead.

If anything is clear by now, it is that Ricky is anything but a
professional programmer.

-- 
The randomly chosen signature file that would have appeared here is more than 4
lines long.  As such, it violates one or more Usenet RFCs.  In order to remain
in compliance with said RFCs, the actual sig can be found at the following URL:
	http://user.xmission.com/~gazelle/Sigs/RepInsults

[toc] | [prev] | [next] | [standalone]


#139062

From"Rick C. Hodgin" <rick.c.hodgin@gmail.com>
Date2018-12-25 07:59 -0500
Message-ID<pvt9hg$hdq$1@dont-email.me>
In reply to#139054
On 12/25/2018 4:22 AM, Mr Flibble wrote:
> Professional coders don't use rand(); they use <random> instead.

"You might look at <random>, Rick.  It allows multiple separate instances
you seek."

Fixed it for you.  And thank you for the information.  I didn't know
<random> existed.  It's why I ask questions like these.  To learn, and
to be part of a community seeking to help one another.

-- 
Rick C. Hodgin

[toc] | [prev] | [next] | [standalone]


#139073

FromMr Flibble <flibbleREMOVETHISBIT@i42.co.uk>
Date2018-12-25 21:59 +0000
Message-ID<kLxUD.421404$qL3.43313@fx29.fr7>
In reply to#139062
On 25/12/2018 12:59, Rick C. Hodgin wrote:
> On 12/25/2018 4:22 AM, Mr Flibble wrote:
>> Professional coders don't use rand(); they use <random> instead.
> 
> "You might look at <random>, Rick.  It allows multiple separate instances
> you seek."
> 
> Fixed it for you.  And thank you for the information.  I didn't know
> <random> existed.  It's why I ask questions like these.  To learn, and
> to be part of a community seeking to help one another.

You are seriously telling me how I should word my replies? What an 
egregious self-righteous cockwomble you are.

/Flibble

-- 
“You won’t burn in hell. But be nice anyway.” – Ricky Gervais

“I see Atheists are fighting and killing each other again, over who 
doesn’t believe in any God the most. Oh, no..wait.. that never happens.” – 
Ricky Gervais

"Suppose it's all true, and you walk up to the pearly gates, and are 
confronted by God," Bryne asked on his show The Meaning of Life. "What 
will Stephen Fry say to him, her, or it?"
"I'd say, bone cancer in children? What's that about?" Fry replied.
"How dare you? How dare you create a world to which there is such misery 
that is not our fault. It's not right, it's utterly, utterly evil."
"Why should I respect a capricious, mean-minded, stupid God who creates a 
world that is so full of injustice and pain. That's what I would say."

[toc] | [prev] | [next] | [standalone]


#139074

Fromnobody@example.org (Scott)
Date2018-12-26 02:43 +0000
Message-ID<5c22ea22.1456732984@news.xmission.com>
In reply to#139073
On Tue, 25 Dec 2018 21:59:45 +0000, Mr Flibble
<flibbleREMOVETHISBIT@i42.co.uk> wrote:

>On 25/12/2018 12:59, Rick C. Hodgin wrote:
>> On 12/25/2018 4:22 AM, Mr Flibble wrote:
>>> Professional coders don't use rand(); they use <random> instead.
>> 
>> "You might look at <random>, Rick.  It allows multiple separate instances
>> you seek."
>> 
>> Fixed it for you.  And thank you for the information.  I didn't know
>> <random> existed.  It's why I ask questions like these.  To learn, and
>> to be part of a community seeking to help one another.
>
>You are seriously telling me how I should word my replies? What an 
>egregious self-righteous cockwomble you are.

Oh, don't be so unkind, Flib. You know that Rick has a cognitive
disability and can only see things that he's expecting to see.

[toc] | [prev] | [next] | [standalone]


#139070

Fromrbowman <bowman@montana.com>
Date2018-12-25 10:15 -0700
Message-ID<g8f6q7Fr3fpU1@mid.individual.net>
In reply to#139050
On 12/24/2018 09:57 PM, Rick C. Hodgin wrote:
>
> Microsoft's Visual C++ comes with source code you can step into for
> their rand() function.  It uses a small block of code.  I had the
> idea to pull that code out and wrap it in a struct or class and then
> have instances.  I think that would work, but I'm not sure if it's
> legal (because it's Microsoft's code) ... so I'm looking for something
> that is available for use, preferably in the public domain.

http://apps.nrbook.com/c/index.html

This is an older edition but the price is right. Chapter 7 covers random 
numbers. Knuth also covers the topic in Volume 2. Microsoft stands on 
the shoulders of giants so I doubt there is anything novel in their 
implementation.

[toc] | [prev] | [next] | [standalone]


#139071

FromKeith Thompson <kst-u@mib.org>
Date2018-12-25 10:14 -0800
Message-ID<lntvj1bhij.fsf@kst-u.example.com>
In reply to#139070
rbowman <bowman@montana.com> writes:
[...]
> http://apps.nrbook.com/c/index.html
>
> This is an older edition but the price is right. Chapter 7 covers random 
> numbers. Knuth also covers the topic in Volume 2. Microsoft stands on 
> the shoulders of giants so I doubt there is anything novel in their 
> implementation.

That's the Numerical Recipes book.  The link doesn't work for me.
Visit http://nrbook.com or http://numerical.recipes for more options.

-- 
Keith Thompson (The_Other_Keith) kst@mib.org  <http://www.ghoti.net/~kst>
Will write code for food.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

[toc] | [prev] | [next] | [standalone]


#139056

FromAnton Shepelev <anton.txt@g{oogle}mail.com>
Date2018-12-25 13:35 +0300
Message-ID<20181225133531.f6f8c12787fb01e983af1a57@g{oogle}mail.com>
In reply to#139043
Rick C. Hodgin:

>Is there an equivalent of a multi-channel rand() function
>that enables multiple simultaneous separate pseudo-random
>number generators by some- thing like a handle or instance
>of each in the standard library?

You can pick one of the published methods from

   https://en.wikipedia.org/wiki/List_of_random_number_generators

and implement it yourself.

-- 
()  ascii ribbon campaign - against html e-mail
/\  http://preview.tinyurl.com/qcy6mjc [archived]

[toc] | [prev] | [next] | [standalone]


#139058

Fromfir <profesor.fir@gmail.com>
Date2018-12-25 02:56 -0800
Message-ID<1c746c4c-06bf-419a-808b-4df5bec954d6@googlegroups.com>
In reply to#139056
W dniu wtorek, 25 grudnia 2018 11:35:40 UTC+1 użytkownik Anton Shepelev napisał:
> Rick C. Hodgin:
> 
> >Is there an equivalent of a multi-channel rand() function
> >that enables multiple simultaneous separate pseudo-random
> >number generators by some- thing like a handle or instance
> >of each in the standard library?
> 
> You can pick one of the published methods from
> 
>    https://en.wikipedia.org/wiki/List_of_random_number_generators
> 
> and implement it yourself.
> 

stupidity needs a defence not 'legitimization'

and all those people answering to spamer risk are like seeps ruled by idiot

this imbecill sheppard will lead you to fields od deep stupidity, do you really want that - respect minimal inteligence, kick this dumbass in the ass 

(said fir)

[toc] | [prev] | [next] | [standalone]


#139064

From"Rick C. Hodgin" <rick.c.hodgin@gmail.com>
Date2018-12-25 08:02 -0500
Message-ID<pvt9lq$hdq$2@dont-email.me>
In reply to#139056
On 12/25/2018 5:35 AM, Anton Shepelev wrote:
> Rick C. Hodgin:
> 
>> Is there an equivalent of a multi-channel rand() function
>> that enables multiple simultaneous separate pseudo-random
>> number generators by some- thing like a handle or instance
>> of each in the standard library?
> 
> You can pick one of the published methods from
> 
>     https://en.wikipedia.org/wiki/List_of_random_number_generators
> 
> and implement it yourself.

Thank you, Anton.

-- 
Rick C. Hodgin

[toc] | [prev] | [next] | [standalone]


#139059

FromBart <bc@freeuk.com>
Date2018-12-25 11:52 +0000
Message-ID<ERoUD.65266$M61.27916@fx19.am4>
In reply to#139043
On 25/12/2018 00:54, Rick C. Hodgin wrote:
> Is there an equivalent of a multi-channel rand() function that enables
> multiple simultaneous separate pseudo-random number generators by some-
> thing like a handle or instance of each in the standard library?
> 

The results are supposed to be random. So does it matter if a single 
random number producer is shared between multiple consumers?

(I can see it being a problem with debugging, when you want each 
consumer to see the same sequence on each run regardless of how many 
other consumers there are.

But for such a case, it might be possible to rig something up to make 
that happen.)


-- 
bart

[toc] | [prev] | [next] | [standalone]


#139060

FromAnton Shepelev <anton.txt@g{oogle}mail.com>
Date2018-12-25 14:58 +0300
Message-ID<20181225145802.66867de9f75eff33f9e8c991@g{oogle}mail.com>
In reply to#139059
Bart to Rick C. Hodgin:

>>Is there an equivalent of a multi-channel rand() function
>>that enables multiple simultaneous separate pseudo-random
>>number generators by something like a handle or instance
>>of each in the standard library?
>
>The results are supposed to be random.  So does it matter
>if a single random number producer is shared between
>multiple consumers?

How about thread separation?

-- 
()  ascii ribbon campaign - against html e-mail
/\  http://preview.tinyurl.com/qcy6mjc [archived]

[toc] | [prev] | [next] | [standalone]


#139061

FromRichard Damon <Richard@Damon-Family.org>
Date2018-12-25 06:59 -0500
Message-ID<hYoUD.317929$GZ9.172380@fx45.iad>
In reply to#139059
On 12/25/18 6:52 AM, Bart wrote:
> On 25/12/2018 00:54, Rick C. Hodgin wrote:
>> Is there an equivalent of a multi-channel rand() function that enables
>> multiple simultaneous separate pseudo-random number generators by some-
>> thing like a handle or instance of each in the standard library?
>>
> 
> The results are supposed to be random. So does it matter if a single
> random number producer is shared between multiple consumers?
> 
> (I can see it being a problem with debugging, when you want each
> consumer to see the same sequence on each run regardless of how many
> other consumers there are.
> 
> But for such a case, it might be possible to rig something up to make
> that happen.)
> 

The results are supposed to be PSEUDO-RANDOM, and repeatable (by
starting with the same seed). I have built some games where a level is
randomly created, but rather than save the entire level, I will first
get somehow a random seed, remember it, and then use it to seed a
specific random number generator. By reusing that remembered seed, and a
bit of information about state changes on the level, I can recreate the
level.

[toc] | [prev] | [next] | [standalone]


#139066

From"Rick C. Hodgin" <rick.c.hodgin@gmail.com>
Date2018-12-25 08:05 -0500
Message-ID<pvt9su$hdq$4@dont-email.me>
In reply to#139061
On 12/25/2018 6:59 AM, Richard Damon wrote:
> On 12/25/18 6:52 AM, Bart wrote:
>> On 25/12/2018 00:54, Rick C. Hodgin wrote:
>>> Is there an equivalent of a multi-channel rand() function that enables
>>> multiple simultaneous separate pseudo-random number generators by some-
>>> thing like a handle or instance of each in the standard library?
>>>
>>
>> The results are supposed to be random. So does it matter if a single
>> random number producer is shared between multiple consumers?
>>
>> (I can see it being a problem with debugging, when you want each
>> consumer to see the same sequence on each run regardless of how many
>> other consumers there are.
>>
>> But for such a case, it might be possible to rig something up to make
>> that happen.)
>>
> 
> The results are supposed to be PSEUDO-RANDOM, and repeatable (by
> starting with the same seed). I have built some games where a level is
> randomly created, but rather than save the entire level, I will first
> get somehow a random seed, remember it, and then use it to seed a
> specific random number generator. By reusing that remembered seed, and a
> bit of information about state changes on the level, I can recreate the
> level.

That's something similar to what I'm seeking to do, so its replicable
without the variation of user interaction and timing affecting the draw
from the single stream, but rather for each to have their own streams,
so the timing of user event sequences will not be a factor.

-- 
Rick C. Hodgin

[toc] | [prev] | [next] | [standalone]


#139065

From"Rick C. Hodgin" <rick.c.hodgin@gmail.com>
Date2018-12-25 08:04 -0500
Message-ID<pvt9pp$hdq$3@dont-email.me>
In reply to#139059
On 12/25/2018 6:52 AM, Bart wrote:
> On 25/12/2018 00:54, Rick C. Hodgin wrote:
>> Is there an equivalent of a multi-channel rand() function that enables
>> multiple simultaneous separate pseudo-random number generators by some-
>> thing like a handle or instance of each in the standard library?
>>
> 
> The results are supposed to be random. So does it matter if a single random 
> number producer is shared between multiple consumers?

I had that thought.  I'm currently writing a game, and the interplay
between two or more simultaneous players will cause the random seq-
uences each player receives to not be replicable, short of storing the
full history of moves.

> (I can see it being a problem with debugging, when you want each consumer to 
> see the same sequence on each run regardless of how many other consumers 
> there are.
> 
> But for such a case, it might be possible to rig something up to make that 
> happen.)

I don't think it matters for gameplay, but it does matter for debug-
ging and analysis / diagnosis (as you indicate).

-- 
Rick C. Hodgin

[toc] | [prev] | [next] | [standalone]


#139081

FromBart <bc@freeuk.com>
Date2018-12-26 15:48 +0000
Message-ID<bpNUD.21754$X_3.4267@fx01.am4>
In reply to#139043
On 25/12/2018 00:54, Rick C. Hodgin wrote:
> Is there an equivalent of a multi-channel rand() function that enables
> multiple simultaneous separate pseudo-random number generators by some-
> thing like a handle or instance of each in the standard library?

This doesn't seem too hard, but it's obviously not in the standard 
library (which AFAIK only has rand()). Example:

-------------------
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

typedef uint64_t u64;
typedef u64* Randgen;

Randgen new_randgen(u64 seed1, u64 seed2) {
// needs two 64-bit non-zero seeds
     Randgen s;

     s=malloc(sizeof(u64)*2);
     if (s==NULL) {
         return s;
     }
     s[0]=seed1;
     s[1]=seed2;
     return s;
}

void free_randgen(Randgen s) {
     free(s);
}

u64 random(Randgen s) {
// based on 'xorshift128+'
     u64 x = s[0];
     u64 const y = s[1];
     s[0] = y;
     x ^= x << 23; // a
     s[1] = x ^ y ^ (x >> 17) ^ (y >> 26); // b, c
     return s[1] + y;
}

int main(void) {
     u64 a;
     Randgen r1,r2,r3;

     r1=new_randgen(374646464,84747774);
     r2=new_randgen(374646464,84747774);
     r3=new_randgen(374646464,84747774);

     for (int i=0; i<10; ++i) {
         printf("%d %016llX %016llX %016llX\n",i,
             random(r1), random(r2), random(r3));
     }

     free_randgen(r1);
     free_randgen(r2);
     free_randgen(r3);

}
-----------------------

All three streams show the same results because I've used the same seed 
for each.

(To reset a stream R to a new seed, either free R and set R to a new 
generator, or change the two u64s that R points to, or provide a 
function for that.

However this depends entirely on the PRNG used. The point of my example 
is to show how easy it is to superimpose a 'multi-channel' API on a 
single-stream PRNG.)

-- 
bart

[toc] | [prev] | [next] | [standalone]


Page 1 of 5  [1] 2 3 4 5  Next page →

Back to top | Article view | comp.lang.c


csiph-web