C++ Logo

std-proposals

Advanced search

[std-proposals] Seedsequence is to restrictive

From: Magnus Fromreide <magfr_at_[hidden]>
Date: Thu, 5 Jun 2025 21:48:27 +0200
Hello.

When trying to initialize a random engine I found that the concept
Seed sequence [rand.req.seedseq] is a lot more restrictive than any use
of it in the standard requires.

This also seems to be part of what P0205 tried to accomplish, but my purpose
is to minimize the requirements placed on seed sequences even if the goals of
P0205 are laudable.



The only place where a seed sequence is used is in the initialization of
a random number engine ([rand.req.eng]), specifically in [tab:rand.req.eng]
and there it is explicitly stated that only a single call to q.generate is
performed on the passed seed sequence.

Thus I think that, as a DR going all the way back to C++11, I think

S()
S(ib, ie)
S(il)
r.size()
r.param(ob)

should be removed from [tab:rand.req.seedseq] and §2 should stop mentioning
r, ib, ie, ob, and il

as that leaves us with what the rest of the standard actually uses.

I also think [rand.req.seedseq] §1 should be changed from

A seed sequence is an object that consumes a sequence of integer-valued data
and produces a requested number of unsigned integer values i, 0 ≤ i < 2^32,
based on the consumed data

to

A seed sequence is an object that produces a requested number of unsigned
integer values i, 0 ≤ i < 2^32




The end result of this is that it allows the use of hardware random
number generators to directly seed random number engines, somehing that
the current standard forbids as the initialization seqences have to be
copyable using the rather clunky r.size and r.param methods.

/MF

Received on 2025-06-05 19:50:47