public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Oliver Kullmann <o.kullmann@swansea.ac.uk>
To: Martin Sebor <msebor@gmail.com>
Cc: <gcc-help@gcc.gnu.org>
Subject: Re: where are the implementations for <random>?
Date: Tue, 11 Apr 2017 20:17:00 -0000	[thread overview]
Message-ID: <20170411201729.GA18654@csltok.swansea.ac.uk> (raw)
In-Reply-To: <20170411182615.GA16536@csltok.swansea.ac.uk>

> Now only missing seeding for std::mt19937_64.
> 
> This seems most complicated.
> Apparently it is in
> https://gcc.gnu.org/viewcvs/gcc/trunk/libstdc%2B%2B-v3/include/bits/random.tcc?revision=246542&view=markup
> 
> Lines 346 - 389.
> 
> I would guess that this functionality is most specialised, and most likely to be different
> for different compilers.
> 
> Really a pitty that this was not standardised.
> 

The code at Lines 346 - 389 for the seed-member of the
mersenne_twister_engine doesn't look too bad except of two aspects: What
is

 - __detail::_Shift ?
 - __detail::__mod  ?

It seems that apart from these functions, everything else is just
arithmetic of bit-logic.

And the creation of that sequence in Line 360:
  __q.generate(__arr + 0, __arr + __n * __k);
actually seems to be defined by the standard, so that can be used.

ACTUALLY, I just realise that even if I can code the above myself, I
couldn't use the Mersenne twister from the standard library, since
apparently the only way of setting the internal state is by
*constants*??

All what there is seems to be
http://www.cplusplus.com/reference/random/mersenne_twister_engine/
template <class UIntType, size_t w, size_t n, size_t m, size_t r,
          UIntType a, size_t u, UIntType d, size_t s,
          UIntType b, size_t t,
          UIntType c, size_t l, UIntType f>
  class mersenne_twister_engine;
and that has the state, which is set by the seed-member-function, only as template parameter.

So I need to implement the Mersenne twister apparently myself.
Or perhaps I don't understand that yet properly.

Perhaps the seed function has nothing to do with those template parameters, which are the
parameters of the engine, while the seed sets only the "internal state", and that perhaps
can be done explicitly by calling some std-library facility?

Would be thankfor for any help.

Oliver

  reply	other threads:[~2017-04-11 20:17 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-09 17:31 Oliver Kullmann
2017-04-09 18:24 ` Marc Glisse
2017-04-09 23:32   ` Martin Sebor
2017-04-11 13:03     ` Oliver Kullmann
2017-04-11 18:26       ` Oliver Kullmann
2017-04-11 20:17         ` Oliver Kullmann [this message]
2017-04-11 20:27           ` Jonathan Wakely
2017-04-12  3:41             ` Oliver Kullmann
2017-04-12  5:01               ` Oliver Kullmann
2018-12-21 12:34 ` wrong sha512 values for 7.4.0 ? Oliver Kullmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170411201729.GA18654@csltok.swansea.ac.uk \
    --to=o.kullmann@swansea.ac.uk \
    --cc=gcc-help@gcc.gnu.org \
    --cc=msebor@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).