Logo

Programming-Idioms

History of Idiom 15 > diff from v28 to v29

Edit summary for version 29 by :
New Csharp implementation by user [zehberk]

Version 28

2016-02-16, 16:14:27

Version 29

2016-02-16, 17:56:27

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
System;
Code
Random r = new Random();
return r.next(a, b + 1);
Comments bubble
Make sure to add 1 to the second argument of next, as it is not inclusive by default.
Doc URL
https://msdn.microsoft.com/en-us/library/system.random%28v=vs.110%29.aspx