项目作者: circlebubble

项目描述 :
Give you a result from random calculation by decimal scoring
高级语言: JavaScript
项目地址: git://github.com/circlebubble/chance.git
创建时间: 2019-08-12T05:26:40Z
项目社区:https://github.com/circlebubble/chance

开源协议:MIT License

下载


Chance

Give you a result from random calculation by decimal scoring

Usage

Use NPM to install zero-chance

  1. $ npm install zero-chance

Import and create config on your project :

  1. import Chance from 'zero-chance'
  2. const weights = [
  3. {
  4. weight: 0.001,
  5. title: 'Some title',
  6. description: 'Some description'
  7. },
  8. {
  9. weight: 20.40,
  10. title: 'Some title',
  11. description: 'Some description'
  12. },
  13. ... so on
  14. ]
  15. const simple = Chance(weights)
  16. console.log(simple) // 1 <-- result of random, given number by highest probability
  17. /**
  18. * Or, you can show any detail on result with option
  19. */
  20. const result = Chance(weights, {
  21. detail: true
  22. })
  23. console.log(result)
  24. // Given result by highest probability
  25. // {
  26. // index: 1,
  27. // weight: 0.001,
  28. // title: 'Some title',
  29. // description: 'Some description'
  30. // }

License

This project under MIT License