KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Can somebody verify this method. I need a long type number inside a range of two longs. I use the .NET Random.Next(min, max) function which return int's. Is my reasoning correct if I simply divide the long by 2, generate the random number and finally multiply it by 2 again? Or am I too enthusiastic... I understand that my random resolution will decrease but are there any other mistakes which will lead to no such a random number. long min = st.MinimumTime.Ticks; //long is Signed 64-bit integer long max = st.MaximumTime.Ticks; int minInt = (int) (min / 2); //int is Signed 64-bit integer int maxInt = (int) (max / 2); //int is Signed 64-bit integer Random random = new Random(); int randomInt = random.Next(minInt, maxInt); long randomLong = (randomInt * 2);
Tags (comma-separated)
Save Edits
Cancel