Logo

Programming-Idioms

History of Idiom 15 > diff from v6 to v7

Edit summary for version 7 by :

Version 6

2015-08-20, 15:38:01

Version 7

2015-08-21, 08:54:09

Idiom #15 Pick uniformly a random integer in [a..b]

Pick a random integer greater than or equals to a, inferior or equals to b. Precondition : a < b.

Idiom #15 Pick uniformly a random integer in [a..b]

Pick a random integer greater than or equals to a, inferior or equals to b. Precondition : a < b.

Imports
import 'dart:math';
Code
int pick(int a, int b) => a + new Random().nextInt(b - a + 1);
Demo URL
https://dartpad.dartlang.org/c45bb7de8d83dd80e37e