Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

3
  • 40
    Just to add a note, if you are using NextDouble() and don't want the lower bound to be zero. You multiply by the difference between the higher bound and the lower bound, then add the difference between the lower bound and zero. So for -1 to 1 double rDouble = (r.NextDouble()*2)-1.0; Commented Oct 28, 2013 at 20:03
  • 4
    Or a simplified double generator in the range of -1.0 and 1.0: Double randDoubleY = new Random().Next(-100, 100) / 100.0D; Commented Dec 15, 2018 at 21:29
  • 1
    Random() uses a time-dependent seed, but writing that out explicitly is better for readability. Commented Mar 10, 2019 at 5:50