Skip to content

[ROOT-9733] TRandom3 does not implement perfectly a Mersenne Twister PRNG #14581

Open
@vepadulano

Description

@vepadulano

Check duplicate issues.

  • Checked for duplicates

Description

From https://its.cern.ch/jira/browse/ROOT-9733

The {{TRandom3}} is a random number engine based on Mersenne Twister algorithm, defined in {{TRandom3.cxx}}. Since 2002 (see commit 026ec9c0f458be61825e7335ec51e115ec6cbf4c), an eventual zero return value is discarded by {{TRandom3::Rndm()}}. This does not allow the algorithm to return the same sequence of the C++11 standard implementation {{std::mt19937}} (when seeded with the same value - except for seed zero, since handled in a special way by {{TRandom3::SetSeed()}} - and multiplied by 2^-32).

A related mistake is present also in the description of the class, where it states the algorithm period to be 2^19937 - 1. If you discard the zeros, of course the period will be (very slightly) less than it.

In conclusion, {{TRandom3}} is an imperfect implementation of the Mersenne Twister 32-bit algoritm. Furthermore, the documentation does not explain this small difference.

 

Reproducer

As per the description

ROOT version

Any

Installation method

Any

Operating system

Any

Additional context

No response

Metadata

Metadata

Assignees

Type

No type

Projects

Status

PR is open

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions