git.iko.soy/rowtype-yoga/psfp
on 4516421 help sign in
113 lines 4.4 kB history raw
1// Generated by purs version 0.13.6
2"use strict";
3var Control_Bind = require("../Control.Bind/index.js");
4var Control_Monad_ST_Internal = require("../Control.Monad.ST.Internal/index.js");
5var Data_Array_ST = require("../Data.Array.ST/index.js");
6var Data_Boolean = require("../Data.Boolean/index.js");
7var Data_EuclideanRing = require("../Data.EuclideanRing/index.js");
8var Data_Functor = require("../Data.Functor/index.js");
9var Data_Int = require("../Data.Int/index.js");
10var Data_Ord = require("../Data.Ord/index.js");
11var Random_LCG = require("../Random.LCG/index.js");
12var Random = function (Ord0, random, randomR) {
13 this.Ord0 = Ord0;
14 this.random = random;
15 this.randomR = randomR;
16};
17var randomsF = function (dictRandom) {
18 return function (f) {
19 return function (i) {
20 return function (seed) {
21 var fill = function (arr) {
22 return function __do() {
23 var seedref = Control_Monad_ST_Internal["new"](seed)();
24 return Control_Monad_ST_Internal["for"](0)(i)(function (v) {
25 return function __do() {
26 var seed$prime = Control_Monad_ST_Internal.read(seedref)();
27 var rp = f(seed$prime);
28 return Control_Bind.discard(Control_Bind.discardUnit)(Control_Monad_ST_Internal.bindST)(Data_Functor["void"](Control_Monad_ST_Internal.functorST)(Control_Monad_ST_Internal.write(rp.newSeed)(seedref)))(function ($dollar__unused) {
29 return Data_Functor["void"](Control_Monad_ST_Internal.functorST)(Data_Array_ST.push(rp.newVal)(arr));
30 })();
31 };
32 })();
33 };
34 };
35 return Data_Array_ST.withArray(fill)([ ])();
36 };
37 };
38 };
39};
40var randomR = function (dict) {
41 return dict.randomR;
42};
43var randomRs = function (dictRandom) {
44 return function (min) {
45 return function (max) {
46 return randomsF(dictRandom)(randomR(dictRandom)(min)(max));
47 };
48 };
49};
50var random = function (dict) {
51 return dict.random;
52};
53var randomInt = new Random(function ($dollar__unused) {
54 return Data_Ord.ordInt;
55}, function (seed) {
56 var newSeed = Random_LCG.lcgNext(seed);
57 return {
58 newVal: Random_LCG.unSeed(newSeed),
59 newSeed: newSeed
60 };
61}, function (min) {
62 return function (max) {
63 return function (seed) {
64 if (min > max) {
65 return randomR(randomInt)(max)(min)(seed);
66 };
67 if (Data_Boolean.otherwise) {
68 var rp = random(randomInt)(seed);
69 var newVal = Data_EuclideanRing.mod(Data_EuclideanRing.euclideanRingInt)(rp.newVal)((max - min | 0) + 1 | 0) + min | 0;
70 return {
71 newVal: newVal,
72 newSeed: rp.newSeed
73 };
74 };
75 throw new Error("Failed pattern match at Random.PseudoRandom (line 33, column 1 - line 42, column 55): " + [ min.constructor.name, max.constructor.name, seed.constructor.name ]);
76 };
77 };
78});
79var randomNumber = new Random(function ($dollar__unused) {
80 return Data_Ord.ordNumber;
81}, function (seed) {
82 var intRp = random(randomInt)(seed);
83 var newVal = Data_Int.toNumber(intRp.newVal) / Data_Int.toNumber(Random_LCG.lcgM);
84 return {
85 newVal: newVal,
86 newSeed: intRp.newSeed
87 };
88}, function (min) {
89 return function (max) {
90 return function (seed) {
91 if (min > max) {
92 return randomR(randomNumber)(max)(min)(seed);
93 };
94 if (Data_Boolean.otherwise) {
95 var rp = random(randomNumber)(seed);
96 var newVal = rp.newVal * (max - min) + min;
97 return {
98 newVal: newVal,
99 newSeed: rp.newSeed
100 };
101 };
102 throw new Error("Failed pattern match at Random.PseudoRandom (line 44, column 1 - line 55, column 47): " + [ min.constructor.name, max.constructor.name, seed.constructor.name ]);
103 };
104 };
105});
106module.exports = {
107 Random: Random,
108 random: random,
109 randomR: randomR,
110 randomRs: randomRs,
111 randomInt: randomInt,
112 randomNumber: randomNumber
113};