Skip to content

Instantly share code, notes, and snippets.

@bradjolicoeur
Created March 28, 2019 15:54
Show Gist options
  • Save bradjolicoeur/1a7ee4e47911a46f339f87e7e7397744 to your computer and use it in GitHub Desktop.
Save bradjolicoeur/1a7ee4e47911a46f339f87e7e7397744 to your computer and use it in GitHub Desktop.
Extension method that creates a random negative or positive value
using System;
namespace GenerateLatLon.Helpers
{
public static class RandomHelper
{
public static int NegativePositive(this Random r)
{
int iNum;
iNum = r.Next(-30, 50); //put whatever range you want in here from negative to positive
if (iNum == 0)
{
iNum++; //to avoid divide by zero
}
return iNum / (int)Math.Abs(iNum);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment