💾 Archived View for p.d2evs.net › 1582141222.ha captured on 2024-08-31 at 14:17:30.
⬅️ Previous capture (2024-03-21)
-=-=-=-=-=-=-
use crand = crypto::random; use math::random; use fmt; export fn main() void = { let seed = 0u64; crand::buffer(&seed: *[8]u8); let rand = random::init(seed); def X = 10000; // number of trials def INCR = 0.01; // how much better you get at a toss after each attempt def MAX = 0.1; // 1.0 - max probability for an individual attempt // set Y to 5 manually to check 5 tosses. i can't be bothered to do any // of this properly for (let Y = 10z; Y < 100; Y += 10) { let n = 0z; let STATE = true; for (let i = 0z; i < X; i += 1) { if (STATE) n += Y * ((1.0 - MAX) / INCR): size; let ns: [100]f64 = [if (STATE) 1.0 else 0.0...]; for (let streak = 1z; streak <= Y; streak += 1) { if (!STATE && ns[streak - 1] < 1.0) ns[streak - 1] += INCR; if (random::f64rand(&rand) >= ns[streak - 1] - MAX) streak = 0z; n += 1; }; }; fmt::println("stateless", Y, n: f64 / X: f64)!; n = 0z; let STATE = false; for (let i = 0z; i < X; i += 1) { if (STATE) n += Y * ((1.0 - MAX) / INCR): size; let ns: [100]f64 = [if (STATE) 1.0 else 0.0...]; for (let streak = 1z; streak <= Y; streak += 1) { if (!STATE && ns[streak - 1] < 1.0) ns[streak - 1] += INCR; if (random::f64rand(&rand) >= ns[streak - 1] - MAX) streak = 0z; n += 1; }; }; fmt::println("states", Y, n: f64 / X: f64)!; }; };