fork(1) download
  1. const A = [0,7,8,15,16,23,24,31]
  2. const B = [1,2,3,4,5,6,25,26,27,28,29,30,9,17,22 ]
  3. const C = [10,11,12,13,18,19,20,21, 14]
  4.  
  5. function shuffleBoard(length) {
  6. const result = []
  7.  
  8. for(let i = 0; i < length; i += 1) {
  9. while (true) {
  10. let bucket = null
  11. let rand = Math.random()
  12. if (rand < 0.5) {
  13. bucket = A
  14. } else if (rand < 0.95) {
  15. bucket = B
  16. } else {
  17. bucket = C
  18. }
  19.  
  20. const pick = bucket[Math.floor(Math.random() * bucket.length)]
  21.  
  22. if (!result.slice(-6).includes(pick)) {
  23. result.push(pick)
  24. break
  25. }
  26. }
  27. }
  28.  
  29. return result
  30. }
  31.  
  32. function validate(result) {
  33. const ratios = {
  34. 'A': result.filter(xs => A.includes(xs)).length / result.length,
  35. 'B': result.filter(xs => B.includes(xs)).length / result.length,
  36. 'C': result.filter(xs => C.includes(xs)).length / result.length,
  37. }
  38.  
  39. return ratios
  40. }
  41.  
  42. const result = shuffleBoard(5000)
  43. console.log(JSON.stringify(validate(result)))
  44.  
  45.  
Success #stdin #stdout 0.05s 18976KB
stdin
Standard input is empty
stdout
{"A":0.4406,"B":0.4966,"C":0.0628}