Showing posts with label Squeak. Show all posts
Showing posts with label Squeak. Show all posts

Monday, January 13, 2025

SplitMix64

 


If you need a PRNG to generate very very very big integers, the SplitMix64Random package is what you need! Compatible with Squeak 6.0.

It's a well-known fact that PRNGs using floats internally show gaps when generating ultra big integers : the precision of floats being finite, there are big numbers they will never be able to generate.

So here's an implementation of the SplitMix64 pseudo-random number generator. It is very fast, has a period of 2^64 and passes the Big Crush, DieHard and TestU012 standard statistical test suites.

However, the SplitMix64 PRNG should NOT be used for cryptographic or security applications!

It is adequate for everyday use, such as Monte Carlo algorithms and randomized data where speed is essential. It is also efficient at dealing with very large random integer values as it circumvents the problem induced by floats having limited precision thus creating gaps between the possible large integers that could theoretically be generated.

Originally created by Sebasto Vigna, SplitMix64 is based on SplittableRandom in Java 8.

Useful references : 

http://xorshift.di.unimi.it/splitmix64.c

https://docs.oracle.com/javase/8/docs/api/java/util/SplittableRandom.html

https://github.com/lemire/testingRNG 

P.S. As a quick-and-dirty visual verification, you can use the following code in a workspace to generate an image similar to the one at the top of this post:

"
VISUAL analysis of a Random Number Generator


References:
https://www.random.org/analysis/
https://boallen.com/random-numbers.html
"

| form colors yourFavoriteRNG size |

size := 512.
yourFavoriteRNG := Random new.

colors := Array with: Color white with: Color black.
form := Form extent: size@size depth: 32.

0 to: (size-1) do: [ :x |
    0 to: (size-1) do: [ :y | form colorAt: (x@y) put: (colors atRandom: yourFavoriteRNG) ] ].
PNGReadWriter putForm: form onFileNamed: 'test.png'.

Below is the image generated with the infamous PHP pseudo-random number generator:

ScriptManager

 


A new version of the ScriptManager package is available on SqueakSource!

However, note that this version works for Squeak 6.0 as I had to correct a bug (related to fonts and preferences) introduced by the Pharo port.

Enjoy!

MySQL Driver

 


I have updated the MySQL driver package on SqueakSource.

I have done some serious cleanup : removing unused classes and instance variables, deprecating unsent methods, reformatting some of the code, fixing many 'lint rules' errors and warnings, performed some minor optimizations, making some parts of the code port-friendly as a first step to share only one version of this package for Squeak, Cuis and Pharo.

This has been tested on Squeak 6.0 with MySQL 5.7 (Windows) and 8.3.0 (Linux).

Now, all I'd need is for some interested Cuis developer to create a compatibility package for ScaledDecimal (so FixedDecimal loads properly).  I am more than willing to make the package portable for Cuis as a first step (before working on Pharo) but I need a ScaledDecimal class that could be loaded as a package.

Juan, are you there? 😉