Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

random_device-question

6 views
Skip to first unread message

Bonita Montero

unread,
Oct 12, 2019, 3:36:27 AM10/12/19
to
Is there any guarantee the standard makes that random_device shoudn't
start at the same internal state for all new threads, i.e. the output
of the following code is likey to be different on both lines?

#include <iostream>
#include <mutex>
#include <random>
#include <thread>

using namespace std;

int main()
{
auto thr = []()
{
static mutex mtx;
random_device rd;
mtx.lock();
cout << rd() << endl;
mtx.unlock();
};
thread t1( thr );
thread t2( thr );
t1.join();
t2.join();
}

Melzzzzz

unread,
Oct 12, 2019, 3:40:00 AM10/12/19
to
On 2019-10-12, Bonita Montero <Bonita....@gmail.com> wrote:
> Is there any guarantee the standard makes that random_device shoudn't
> start at the same internal state for all new threads, i.e. the output
> of the following code is likey to be different on both lines?

No.


--
press any key to continue or any other to quit...
U ničemu ja ne uživam kao u svom statusu INVALIDA -- Zli Zec
Na divljem zapadu i nije bilo tako puno nasilja, upravo zato jer su svi
bili naoruzani. -- Mladen Gogala

Bonita Montero

unread,
Oct 12, 2019, 3:40:30 AM10/12/19
to
Oh, wrong newsgroup.

Bonita Montero

unread,
Oct 12, 2019, 3:41:18 AM10/12/19
to
>> Is there any guarantee the standard makes that random_device shoudn't
>> start at the same internal state for all new threads, i.e. the output
>> of the following code is likey to be different on both lines?

> No.

Maybe, but I don't believe _you_ since you're an idiot.

Melzzzzz

unread,
Oct 12, 2019, 5:10:12 AM10/12/19
to
On 2019-10-12, Bonita Montero <Bonita....@gmail.com> wrote:
I guess that highly depends on compiler and OS... why don't you try out?

Bonita Montero

unread,
Oct 12, 2019, 5:30:14 AM10/12/19
to
>> Maybe, but I don't believe _you_ since you're an idiot.

> I guess that highly depends on compiler and OS...
> why don't you try out?

This wouldn't help answering my question.

Melzzzzz

unread,
Oct 12, 2019, 5:39:41 AM10/12/19
to
On 2019-10-12, Bonita Montero <Bonita....@gmail.com> wrote:
You are stupid...

Bonita Montero

unread,
Oct 12, 2019, 5:42:56 AM10/12/19
to
>>> I guess that highly depends on compiler and OS...
>>> why don't you try out?

>> This wouldn't help answering my question.

> You are stupid...

You are stupud because you don't understand that when a standard
library behaves like I wish it may not be portable because this
behaviour might not be specified. So it wouldn't be clever to
rely on this only because an implementation has this behaviour.
Boy, you're always telling stupid stuff. Stop writing about such
things; it's always embarrassing for you.
0 new messages