Logo

Programming-Idioms

History of Idiom 15 > diff from v35 to v36

Edit summary for version 36 by programming-idioms.org:
[Csharp] using

Version 35

2017-02-07, 21:45:31

Version 36

2017-03-07, 10:31: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.

Extra Keywords
choose
Extra Keywords
choose
Imports
System;
Imports
using System;
Code
Random r = new Random();
return r.next(a, b + 1);
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.
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
Doc URL
https://msdn.microsoft.com/en-us/library/system.random%28v=vs.110%29.aspx