Find the answer to your Linux question:
Results 1 to 3 of 3
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Seeded random number differences between different computers


    Just a quick question. Part of a java program I have requires a random number generation to drive Monte Carlo calculations. To recreate identical runs the seed is fixed.

    However, I can not achieve this repeatability when running the program on one server and then on another where they differ in both chipset and OS.

    Am I right in assuming that because of the differences in the chipset (or is it OS - RH, CentOS, Windows?) causes the generation of the random sequence to be different and therefore preventing repeatability.

    Thanks for any advice.

  2. #2
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Saint Paul, MN, USA / CentOS, Debian, Slackware, {Free, Open, Net}BSD, Solaris

    Welcome to the forum.

    I find perl codes to be far shorter than Java, so I coded this perl script:
    #!/usr/bin/env perl
    # @(#) p1	Demonstrate random number sequence.
    use warnings;
    use strict;
    # Set random set to constant.
    foreach ( 1 .. 5 ) {
      print int( rand(10) ), "\n";
    which produces, when run:
    % ./p1
    On one machne:
    OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
    Distribution        : Debian GNU/Linux 5.0.8 (lenny) 
    perl 5.10.0
    same as on:
    OS, ker|rel, machine: Linux, 2.6.32-5-amd64, x86_64
    Distribution        : Debian GNU/Linux 6.0 
    perl 5.10.1
    same as on:
    OS, ker|rel, machine: FreeBSD, 8.0-RELEASE, i386
    perl 5.10.1
    same as on:
    OS, ker|rel, machine: HP-UX, B.11.11, 9000/712
    Distribution        : GenericSysName [HP Release B.11.11] (see /etc/issue)
    perl 5.8.0
    So for different OSs, different revs of perl, 32 vs 64-bit, codes ran the same.

    This does not say anything about your specific Java situation, but it does show that portability is certainly possible with random number sequences.

    Assuming that all other characteristics are constant, this suggests that either the perl developers are very careful about portability, the Java RNG simply does not produce the same sequence from platform to platform, or your code is not as portable as you hoped -- e.g. did you really have the same seed, etc.

    You may get more pertinent answers from Java experts if you posted the shortest Java code that exhibits this problem, along with a few sample results from the different platforms you have used, along with information about those platforms.

    Bets wishes ... cheers, drl
    Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
    90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
    We look forward to helping you with the challenge of the other 10%.
    ( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )

  3. #3
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    There is no guarantee that using a fixed seed will result in the same random number, especially between systems. Often, in order to avoid this (it is a security hole), many implementations will use some other information in combination with the seed to generate what is called entropy in order to assure a more random number distribution. There are also many different random number generators with different properties. Relying upon getting the same number from the same seed for a Monte Carlo routine is NOT a good idea! Go here for more information about random number generators and Monte Carlo routines: Section B -- Selected Computational Methods

    FWIW, my wife is a particle physicist, and is a real expert on Monte Carlo routines since they are a key element in predicting and analyzing the petabytes of data that Fermi Lab and CERN generate when searching for elementary particles.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts