-1

Just a couple general questions I haven't been able to find answers to, and maybe someone with a little more knowledge can help. I haven't used Java in years and can't quite find an answer in the docs. I apologize if it's in there and I just happen to be blind. I did find some answers/discussion on SO to a question that come close to the subject but they didn't quite get there.

Linear congruential generator gives wrong output

I've been asked to evaluate a program that uses Java SplittableRandom class to generate random numbers. Previous versions of the program used the Java Random class.

I'm looking for the multiplier, increment and the power of 2 used for the SplittableRandom class.

Wiki on LCG has the old java.util.Random class constants listed as:

multiplier = 25214903917
increment = 11
modulus = 2^48

https://en.wikipedia.org/wiki/Linear_congruential_generator

Anyone know if they are the same for the SplittableRandom class? Or is SplittableRandom included in that page with a different name I'm not understanding? Also, I can't seem to figure out from the library docs if someone can change those constants in the class implementation. I don't know why anyone would unless they found something with a longer period in which case, they should just implement their own. It doesn't appear from the docs that you can customize the constants but again, I can't quite tell.

I apologize if this is the wrong place. If it needs to go somewhere else, I'll delete and post there.

Dan
  • 758
  • 6
  • 20
  • Have you read https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/SplittableRandom.html ? – Mark Rotteveel Aug 09 '23 at 12:38
  • 2
    And have you read the source code https://github.com/openjdk/jdk/blob/master/src/java.base/share/classes/java/util/SplittableRandom.java which has comments providing more detail than the Javadoc? – tgdavies Aug 09 '23 at 12:43
  • I think that the two implementations work different, so `SplittableRandom` does not use `mulitplier`, `increment` and `modulus` in that exact form. – cyberbrain Aug 09 '23 at 13:05
  • I have dug around in those docs and done some document searches of them but I couldn't really make heads or tails of it yet but I'm still looking. I read in some of the original research publications for the power of 2 lcgs that splittablerandom was of that form and that java.util.random was actually not a power of 2, which is part of what is confusing me with that wiki page. I have not. I didn't realize the source code was available. Thank you for that, I will check it. – Dan Aug 09 '23 at 13:10
  • `SplittableRandom` implements `RandomGenerator` and inherits some basic `nextXxx` methods. In fact, `RandomGenerator` is also implemented by `Random`. I'd go the simple way and just use the same methods. – Rob Spoor Aug 09 '23 at 14:43
  • I was under the impression that they both used the general form LCG `X_n-1 = (aX_n + c) mod m` and that `m` in splittablerandom was = 2^n. I've gotten to more digging (@tgdavies suggestion) into the source code and it seems that the underlying lcg for splittable random is a different lcg with shifts in binary...unless mathematically that formula is the same with just those shifts added in. – Dan Aug 09 '23 at 17:24
  • ...and I'm just trying to understand as well as possible what is going on in the background with the program I've been asked to evaluate. It uses splittablerandom for RNG for an MCMC implementation., which I understand is one of the recommended uses of splittablerandom. I'm not trying to implement a splittablerandom method or weight it against other methods. – Dan Aug 09 '23 at 17:27

0 Answers0