-4

I have the following program:

import java.util.*;
import cern.jet.random.engine.MersenneTwister;
import cern.jet.random.engine.RandomEngine;

public class printy{
    static RandomEngine val = new MersenneTwister( (int)System.currentTimeMillis() );
    System.out.println(var.toString());
}

What is the range in var? It is an integer of what size? Can it ever be 0?

According to the documentation, the seed cannot be 0, but the random INT could be zero. This is due to a (mathematical?) property of how the MersenneTwister is implied in Java?

ShanZhengYang
  • 16,511
  • 49
  • 132
  • 234
  • Why would not you check the source yourself? PS: it also took me 10 seconds to google this https://dst.lbl.gov/ACSSoftware/colt/api/cern/jet/random/engine/MersenneTwister.html – zerkms Jan 18 '17 at 04:32
  • @zerkms So, it is a number from -2147483648 to +2147483648 – ShanZhengYang Jan 18 '17 at 04:52

1 Answers1

1

Straight from the API documentation:

MersenneTwister (MT19937) is one of the strongest uniform pseudo-random number generators known so far; at the same time it is quick. Produces uniformly distributed int's and long's in the closed intervals [Integer.MIN_VALUE,Integer.MAX_VALUE] and [Long.MIN_VALUE,Long.MAX_VALUE], respectively, as well as float's and double's in the open unit intervals (0.0f,1.0f) and (0.0,1.0), respectively.

Specifically...

  • Integers: [-2147483648, 2147483647]
  • Long: [-9223372036854775808, 9223372036854775807]
  • Float: [0.0f, 1.0f]
  • Double: [0.0, 1.0]

***Note:*** These are closed intervals (i.e. endpoints are included) per the documentation. When dealing with Double and Float values, "If one needs (0,1]-random numbers," the article that introduced MT says: "simply discard the zeros."

Austin
  • 8,018
  • 2
  • 31
  • 37