11const selectorFactory = require ( "./index" ) ;
22
33console . log ( "----- Simulating selecting balls from a bag without returning: " ) ;
4- var bagsNormal = selectorFactory . createSimpleSelectorWithoutReplacement ( [
4+ var normalBag = selectorFactory . createSimpleSelectorWithoutReplacement ( [
55 { color :'red' } ,
66 { color :'black' } ,
7- { color :'red' } ,
87] ) ;
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 ( ) ) ;
1311
1412console . 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' } ,
1916] ) ;
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 ( ) ) ;
2720
2821console . 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 ] ) ;
3023var points = Array ( ) ;
3124for ( let i = 0 ; i < 10 ; i ++ )
3225{
33- points . push ( diceSelector . select ( ) ) ;
26+ points . push ( dice . select ( ) ) ;
3427}
3528console . log ( "Total points after 10 rolls: " , points ) ;
3629
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 ++ )
4233{
43- faces . push ( flipSelector . select ( ) ) ;
34+ daisy . getElements ( ) . push ( 'petal' ) ;
4435}
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 ( ) ) ;
4649
4750console . log ( "----- Simulating lucky wheel: each bonus has the same frequency" ) ;
4851var fortuneWheel = selectorFactory . createFrequencySelectorWithReplacement (
@@ -58,22 +61,20 @@ var fortuneWheel = selectorFactory.createFrequencySelectorWithReplacement(
5861 , [ '600$' , 10 ]
5962 , [ '200$' , 10 ]
6063 , [ '350$' , 10 ]
61- , [ '1000$' , 10 ]
6264 ] ///Total frequency is 1200
6365) ;
66+ console . log ( "Prize: " , fortuneWheel . select ( ) ) ;
6467
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 (
7271 [ [ '1000$' , 50 ]
73- , [ '10$' , 9000 ]
72+ , [ '10$' , 5000 ]
7473 ]
75- , 10000 ///base is basispoint
74+ , 10000 ///basispoint based
7675) ;
76+ console . log ( "Prize: " , realWheel . select ( ) ) ;
77+
7778
7879
7980
0 commit comments