How to resolve the algorithm Pseudo-random numbers/Splitmix64 step by step in the Sidef programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Pseudo-random numbers/Splitmix64 step by step in the Sidef programming language

Table of Contents

Problem Statement

Splitmix64 is the default pseudo-random number generator algorithm in Java and is included / available in many other languages. It uses a fairly simple algorithm that, though it is considered to be poor for cryptographic purposes, is very fast to calculate, and is "good enough" for many random number needs. It passes several fairly rigorous PRNG "fitness" tests that some more complex algorithms fail. Splitmix64 is not recommended for demanding random number requirements, but is often used to calculate initial states for other more complex pseudo-random number generators. The "standard" splitmix64 maintains one 64 bit state variable and returns 64 bits of random data with each call. Basic pseudocode algorithm: The returned value should hold 64 bits of numeric data. If your language does not support unsigned 64 bit integers directly you may need to apply appropriate bitmasks during bitwise operations. In keeping with the general layout of several recent pseudo-random number tasks:

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Pseudo-random numbers/Splitmix64 step by step in the Sidef programming language

Source code in the sidef programming language

class Splitmix64(state) {

    define (
        mask64 = (2**64 - 1)
    )

    method next_int {
        var n = (state = ((state + 0x9e3779b97f4a7c15) & mask64))
        n = ((n ^ (n >> 30)) * 0xbf58476d1ce4e5b9 & mask64)
        n = ((n ^ (n >> 27)) * 0x94d049bb133111eb & mask64)
        (n ^ (n >> 31)) & mask64
    }

    method next_float {
        self.next_int / (mask64+1)
    }
}

say 'Seed: 1234567, first 5 values:'
var rng = Splitmix64(1234567)
5.of { rng.next_int.say }

say "\nSeed: 987654321, values histogram:"
var rng = Splitmix64(987654321)
var histogram = Bag(1e5.of { floor(5*rng.next_float) }...)
histogram.pairs.sort.each { .join(": ").say }


  

You may also check:How to resolve the algorithm Set consolidation step by step in the Racket programming language
You may also check:How to resolve the algorithm Execute a system command step by step in the Go programming language
You may also check:How to resolve the algorithm Wireworld step by step in the OCaml programming language
You may also check:How to resolve the algorithm Guess the number step by step in the LOLCODE programming language
You may also check:How to resolve the algorithm Haversine formula step by step in the BBC BASIC programming language