Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Ollhax

Member Since 22 Jan 2012
Offline Last Active Today, 02:19 AM

#5210790 Exclusive maximum in random functions

Posted by Ollhax on 15 February 2015 - 02:28 AM

Hi there! I'm working on some library functions and I've hit a problem. Why do people insist on having random functions (like Random(min, max)) where the max value is excluded?

 

Con's:

  • It's counter-intuitive. Most rookies trip on this at least once.
  • It's less efficient in the approach I was going for.
  • It has weird states like Random(0, 1) being the same as Random(0, 0) (unless one should forbid the latter, which seems only worse). You also can't Randomize through the full positive int range [0-Int32.MaxValue] (which kinda isn't a problem, but still inelegant).

Pro's:

  • Bit simpler when you're randomizing an element out of an array (array[Random(array.Size)]). Basically fits in better in a world where 0 is the starting index.
  • Everyone does it this way, including the System.Random functions (working in C#).

I really don't like a randomization lib being modelled only for indexing arrays, but the fact that everyone does it this way is a much more convincing argument. Before I go make a decision and move on, is there something I'm not thinking about?




PARTNERS