Movatterモバイル変換


[0]ホーム

URL:



This page is a snapshot from the LWG issues list, see theLibrary Active Issues List for more information and the meaning ofCD1 status.

395. inconsistencies in the definitions of rand() and random_shuffle()

Section: 29.7[c.math]Status:CD1Submitter: James KanzeOpened: 2003-01-03Last modified: 2016-01-28

Priority:Not Prioritized

View all otherissues in [c.math].

View all issues withCD1 status.

Discussion:

In 29.7[c.math], the C++ standard refers to the C standard for thedefinition of rand(); in the C standard, it is written that "Theimplementation shall behave as if no library function calls the randfunction."

In 26.7.13[alg.random.shuffle], there is no specification as tohow the two parameter version of the function generates its randomvalue. I believe that all current implementations in fact call rand()(in contradiction with the requirement avove); if an implementation doesnot call rand(), there is the question of how whatever random generatorit does use is seeded. Something is missing.

Proposed resolution:

In [lib.c.math], add a paragraph specifying that the C definition ofrand shal be modified to say that "Unless otherwise specified, theimplementation shall behave as if no library function calls the randfunction."

In [lib.alg.random.shuffle], add a sentence to the effect that "Inthe two argument form of the function, the underlying source ofrandom numbers is implementation defined. [Note: in particular, animplementation is permitted to userand.]

Rationale:

The original proposed resolution proposed requiring the two-argument from ofrandom_shuffle to userand. We don't want to do that, because some existing implementations already use something else: gcc useslrand48, for example. Usingrand presents a problem if the number of elements in the sequence is greater than RAND_MAX.


[8]ページ先頭

©2009-2026 Movatter.jp