1234567891011121314151617181920212223242526272829303132333435(* Claude Code
*
* Copyright (C) 2026 Yoann Padioleau
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public License
* (LGPL) as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*)(* See Hash.mli *)(* Park and Miller's minimal standard, one step: 16807 x mod (2^31 - 1)
* by Schrage's method, every product below 2^31 (127773 = m / 16807,
* 2836 = m mod 16807) *)letm=2147483647letpark_miller(x:int):int=lethi=x/127773andlo=xmod127773inlett=(16807*lo)-(2836*hi)inift>0thentelset+m(* the high bits folded into the low ones: breaks the linearity that
* leaves neighbouring points correlated (see Hash.mli) *)letmix(x:int):int=letx=xlxor(xlsr13)inifx=0then1elsexlethash~(seed:int)(i:int):float=(* 20 bits of point, 10 of seed: below 2^30, positive *)letx=((iland0xfffff)*1024)+(seedland0x3ff)+1inletx=park_miller(mix(park_miller(mix(park_millerx))))in(2.*.float_of_intx/.float_of_intm)-.1.letunit~(seed:int)(i:int):float=(hash~seedi+.1.)/.2.