Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Math.random() explained
- int randomWithRange(int min, int max)
- {
- int range = (max - min) + 1;
- return (int)(Math.random() * range) + min;
- }
- 5
- 2
- 3
- 3
- 2
- 4
- 4
- 4
- 5
- 4
- int randomWithRange(int min, int max)
- {
- int range = Math.abs(max - min) + 1;
- return (int)(Math.random() * range) + (min <= max ? min : max);
- }
- double randomWithRange(double min, double max)
- {
- double range = (max - min);
- return (Math.random() * range) + min;
- }
- double randomWithRange(double min, double max)
- {
- double range = Math.abs(max - min);
- return (Math.random() * range) + (min <= max ? min : max);
- }
Add Comment
Please, Sign In to add comment