Random.ts 647 B

12345678910111213141516171819202122232425
  1. export default class Random
  2. {
  3. public static Range(min: number, max: number, isInt: boolean = true): number
  4. {
  5. //return min + Math.ceil(Math.random() * 1000) % (max - min); //不包含最大值
  6. let del: number = max - min;
  7. if (del > 0)
  8. {
  9. let val: number = min + Math.random() * 0xffffff % del
  10. if (isInt)
  11. {
  12. return Math.floor(val);
  13. }
  14. return val
  15. }
  16. return min;
  17. }
  18. public static GetBool():boolean
  19. {
  20. let temp=Random.Range(0,2);
  21. return temp==1?true:false;
  22. }
  23. }