jherekhealy opened a new pull request, #191:
URL: https://github.com/apache/commons-rng/pull/191

   Dear commons-rng team,
   
   This is a pull request to provide two new random number generators: 
philox4x32 and philox4x64 from https://www.thesalmons.org/john/random123/
   
   Those are quite standard nowadays (part of CUDA, Numpy, default for Pytorch 
on GPU, default for TensorFlow) and there is no official Java implementation. 
The proposed implementation matches Numpy and Python's randomgen numbers. It 
passes all commons-rng unit tests.
   
   Counter-based PRNGs are great for parallelization, as skipping-ahead is 
nearly as fast as a single random number generation, and the counter makes it 
very easy to create subsequences. One has complete control then on how to 
split. 
   
   In addition I also have added two new methods to convert a long to a double 
or two ints two a double in the (0,1) **open** interval. This is useful for 
many applications such as Monte-Carlo simulations, where uniform random numbers 
are mapped to some distribution. One common technique is to rely on the inverse 
cumulative distribution function, which is only defined on the open interval.
   
   Best wishes,
   
   Jherek
   
   P.S.: below are some performance numbers:
   
   ```
   NextDoubleGenerationPerformance.nextDouble                   BASELINE  avgt  
 10   0,390 ±  0,001  ns/op
   NextDoubleGenerationPerformance.nextDouble                        JDK  avgt  
 10  14,578 ±  0,007  ns/op
   NextDoubleGenerationPerformance.nextDouble                PHILOX_4X32  avgt  
 10   7,121 ±  0,007  ns/op
   NextDoubleGenerationPerformance.nextDouble                PHILOX_4X64  avgt  
 10   8,059 ±  0,009  ns/op
   NextDoubleGenerationPerformance.nextDouble                 WELL_512_A  avgt  
 10   4,709 ±  0,005  ns/op
   ```
   As you can see they are not the fastest generators, but are for most 
purposes fast enough and the ease and flexibility of parallelization makes up 
for the generation speed. The 64-bit version could be faster with 
Math.unsignedMultipliedHigh of Java 19. I however found it problematic to use 
an MR-Jar (which would be ideal for this) with Jacoco. 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to