Module

LayeredLayout.JavaRandom

Package
purescript-layered-layout
Repository
markgrafhq/purescript-layered-layout

Faithful PureScript port of java.util.Random.

#Random Source

newtype Random

A Java Random instance: 48-bit seed.

#mkRandom Source

mkRandom :: Number -> Random

Create a Random initialized like new java.util.Random(seed).

#mkRandomBI Source

mkRandomBI :: BigInt -> Random

BigInt-precision version of mkRandom. Use this when threading a

#next Source

next :: Int -> Random -> Int /\ Random

Java's Random.next(bits): advance state, return top bits of state.

#nextDouble Source

nextDouble :: Random -> Number /\ Random

nextDouble() = ((next(26) << 27) | next(27)) / 2^53

#nextLong Source

nextLong :: Random -> Number /\ Random

nextLong() = (next(32) << 32) + next(32)

NOTE: Java's nextLong() returns a 64-bit signed long. Number can only represent integers exactly up to 2^53; for larger magnitudes (like Random(1).nextLong() = -4964420948893066024) low-order bits are silently dropped. Use nextLongBI if the result is going to be re-fed into setSeed/mkRandom.

#nextLongBI Source

nextLongBI :: Random -> BigInt /\ Random

BigInt-precision version of nextLong. Returns the exact 64-bit signed integer value as a BigInt, suitable for feeding back into mkRandomBI without Number precision loss.

Java: ((long)next(32) << 32) + next(32) — both halves are signed 32-bit, so the high half has its top bit interpreted as the sign of the resulting 64-bit value.

#nextBoolean Source

nextBoolean :: Random -> Boolean /\ Random

nextBoolean() = next(1) /= 0

#randomShuffle Source

randomShuffle :: forall a. Random -> Array a -> (Array a) /\ Random

Shuffle by sorting on random barycenters (ELK's randomizeBarycenters).