1
1
const selectorFactory = require ( "./index" ) ;
2
2
3
3
console . log ( "----- Simulating selecting balls from a bag without returning: " ) ;
4
- var bagsNormal = selectorFactory . createSimpleSelectorWithoutReplacement ( [
4
+ var normalBag = selectorFactory . createSimpleSelectorWithoutReplacement ( [
5
5
{ color :'red' } ,
6
6
{ color :'black' } ,
7
- { color :'red' } ,
8
7
] ) ;
9
- console . log ( "Selected ball: " , bagsNormal . select ( ) ) ;
10
- console . log ( "Selected ball: " , bagsNormal . select ( ) ) ;
11
- console . log ( "Selected ball: " , bagsNormal . select ( ) ) ;
12
- console . log ( "Bag now empty, no ball selected: " , bagsNormal . select ( ) ) ;
8
+ console . log ( "Selected ball: " , normalBag . select ( ) ) ;
9
+ console . log ( "Selected ball: " , normalBag . select ( ) ) ;
10
+ console . log ( "Bag now empty, no ball left to be selected: " , normalBag . select ( ) ) ;
13
11
14
12
console . log ( "----- Simulating selecting balls from a bag with returning: " ) ;
15
- var bagsMagic = selectorFactory . createSimpleSelectorWithoutReplacement ( [
16
- { color :'red' } ,
17
- { color :'black' } ,
18
- { color :'red' } ,
13
+ var magicBag = selectorFactory . createSimpleSelectorWithReplacement ( [
14
+ { color :'red' , id :'left' } ,
15
+ { color :'black' , id :'right' } ,
19
16
] ) ;
20
- console . log ( "Selected ball: " , bagsMagic . select ( ) ) ;
21
- console . log ( "Selected ball: " , bagsMagic . select ( ) ) ;
22
- console . log ( "Selected ball: " , bagsMagic . select ( ) ) ;
23
- console . log ( "Still have ball selected: " , bagsMagic . select ( ) ) ;
24
-
25
-
26
-
17
+ console . log ( "Selected ball: " , magicBag . select ( ) ) ;
18
+ console . log ( "Selected ball: " , magicBag . select ( ) ) ;
19
+ console . log ( "Still have balls: " , magicBag . select ( ) ) ;
27
20
28
21
console . log ( "----- Simulating rolling dice: " ) ;
29
- var diceSelector = selectorFactory . createSimpleSelectorWithReplacement ( [ 1 , 2 , 3 , 4 , 5 , 6 ] ) ;
22
+ var dice = selectorFactory . createSimpleSelectorWithReplacement ( [ 1 , 2 , 3 , 4 , 5 , 6 ] ) ;
30
23
var points = Array ( ) ;
31
24
for ( let i = 0 ; i < 10 ; i ++ )
32
25
{
33
- points . push ( diceSelector . select ( ) ) ;
26
+ points . push ( dice . select ( ) ) ;
34
27
}
35
28
console . log ( "Total points after 10 rolls: " , points ) ;
36
29
37
-
38
- console . log ( "----- Simulating flipping coin: " ) ;
39
- var flipSelector = selectorFactory . createSimpleSelectorWithReplacement ( [ 'Head' , 'Tail' ] ) ;
40
- var faces = Array ( ) ;
41
- for ( let i = 0 ; i < 10 ; i ++ )
30
+ console . log ( "----- Simulating a love checker build in daisy: " ) ;
31
+ var daisy = selectorFactory . createSimpleSelectorWithoutReplacement ( [ ] ) ;
32
+ for ( let i = 0 ; i < daisy . getRandomer ( ) . getRandomIntBetween ( 4 , 8 ) ; i ++ )
42
33
{
43
- faces . push ( flipSelector . select ( ) ) ;
34
+ daisy . getElements ( ) . push ( 'petal' ) ;
44
35
}
45
- console . log ( "Coin toss result: " , faces ) ;
36
+ var meter = true ;
37
+ while ( daisy . select ( ) != null )
38
+ {
39
+ meter = ! meter ;
40
+ console . log ( meter ?'He loves me' :'He loves me not' ) ;
41
+ }
42
+ if ( ! meter ) {
43
+ console . log ( 'try another daisy' ) ;
44
+ }
45
+
46
+ console . log ( "----- Simulating flipping coin: " ) ;
47
+ var chigurhCoin = selectorFactory . createSimpleSelectorWithReplacement ( [ 'Head' , 'Tail' ] ) ;
48
+ console . log ( "Your call: " , chigurhCoin . select ( ) ) ;
46
49
47
50
console . log ( "----- Simulating lucky wheel: each bonus has the same frequency" ) ;
48
51
var fortuneWheel = selectorFactory . createFrequencySelectorWithReplacement (
@@ -58,22 +61,20 @@ var fortuneWheel = selectorFactory.createFrequencySelectorWithReplacement(
58
61
, [ '600$' , 10 ]
59
62
, [ '200$' , 10 ]
60
63
, [ '350$' , 10 ]
61
- , [ '1000$' , 10 ]
62
64
] ///Total frequency is 1200
63
65
) ;
66
+ console . log ( "Prize: " , fortuneWheel . select ( ) ) ;
64
67
65
- for ( let i = 0 ; i < 10 ; i ++ )
66
- {
67
- console . log ( "Bonus: " , fortuneWheel . select ( ) ) ;
68
- }
69
-
70
- ///A modified wheel with 0.5% chance to get 1000$, 90 % chance to get 10$, 9.5% to get stuck (select return null) O_O!
71
- var cheatedWheel = selectorFactory . createFrequencySelectorWithReplacement (
68
+ ///A cheated wheel with 0.5% chance to get 1000$, 50 % chance to get 10$, 49.5% to get stuck (select return null)
69
+ console . log ( "A cheated wheel: pretty sure that player won't get big prize!" ) ;
70
+ var realWheel = selectorFactory . createFrequencySelectorWithReplacement (
72
71
[ [ '1000$' , 50 ]
73
- , [ '10$' , 9000 ]
72
+ , [ '10$' , 5000 ]
74
73
]
75
- , 10000 ///base is basispoint
74
+ , 10000 ///basispoint based
76
75
) ;
76
+ console . log ( "Prize: " , realWheel . select ( ) ) ;
77
+
77
78
78
79
79
80
0 commit comments