Created
March 28, 2019 15:54
-
-
Save bradjolicoeur/1a7ee4e47911a46f339f87e7e7397744 to your computer and use it in GitHub Desktop.
Extension method that creates a random negative or positive value
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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