COIN-OR::LEMON - Graph Library

Opened 3 years ago

Closed 5 months ago

#602 closed enhancement (done)

Platform independent pseudo random sequences

Reported by: alpar Owned by: alpar
Priority: major Milestone: LEMON 1.4 release
Component: core Version: hg main
Keywords: Cc:
Revision id:


LEMON's random generator is based on the Mersenne Twister algoritm and it is optimized to 32 and 64 bit architecture. This is fine, except when someone want to obtain reproducible results (for a given initial seed) on each platform. The attached patch provides the following solution to this.

The original Random class becomes a template and goes to the _random_bits namespace, then three typedefs are defined:

  • Random is exactly the same as the class Random was before,
  • Random32 is the 32 bit version (on all platform) and
  • Random64 is the 64 bit version (on all platform).

This solution is fully backward compatible and the only drawback I can see is the documentation - one has to visit the template version to see the detailed API.

What do you think, is the documentation is acceptable in this form? If not, what would be a better solution?

Attachments (3)

602-db1d342a1087.patch (39.1 KB) - added by alpar 3 years ago.
602-026829fdb6d4.patch (7.6 KB) - added by kpeter 6 months ago.
602-04f57dad1b07.patch (7.6 KB) - added by kpeter 5 months ago.

Download all attachments as: .zip

Change History (9)

Changed 3 years ago by alpar

comment:1 Changed 2 years ago by alpar

  • Type changed from defect to enhancement

comment:2 Changed 6 months ago by kpeter

I do like this changeset, we should merge it to the main branch.

I also added a patch [026829fdb6d4] with javadoc improvements (it is on the top of the proposed patch).

Last edited 6 months ago by kpeter (previous) (diff)

Changed 6 months ago by kpeter

comment:3 follow-up: Changed 5 months ago by alpar

I cannot apply 602-026829fdb6d4.patch with --exact, mercurial says this patch is corrupt.

Changed 5 months ago by kpeter

comment:4 in reply to: ↑ 3 Changed 5 months ago by kpeter

Replying to alpar:

I cannot apply 602-026829fdb6d4.patch with --exact, mercurial says this patch is corrupt.

Strange. I can reproduce the issue, but I do not understand its cause. It seems that if I export a changeset after it was modified (e.g. hg commit --amend), then it cannot be imported with --exact. But if I import it without --exact, it works and a new hash ID is added to the commit. If I export this new version, then it can be imported with --exact again. I do not understand why this happens. Maybe due to the Unicode characters I used in the author name? (I use Mercurial 4.3.1 on Ubuntu 17.10)

I recreated the patch as [04f57dad1b07] and tested it, it should work correctly.

Last edited 5 months ago by kpeter (previous) (diff)

comment:5 Changed 5 months ago by alpar

Yes, now it works. Thanks.

comment:6 Changed 5 months ago by alpar

  • Resolution set to done
  • Status changed from new to closed

Changesets [db1d342a1087] and [04f57dad1b07] are pushed to the main branch.

Note: See TracTickets for help on using tickets.