Keep Talking and Nobody Explodes

Keep Talking and Nobody Explodes

Prime Checker
3 Comments
eXish  [author] 30 Dec, 2019 @ 11:45am 
Thanks for letting me know
Dark Heresy 30 Dec, 2019 @ 10:25am 
Also, but this is minor, the odds of generating a prime number vs a nonprime number are not 50/50. This is because the random function generates a number from 1 to 99 (change the first argument to 0 for 50/50 odds)
Dark Heresy 30 Dec, 2019 @ 10:11am 
This module is broken. I've looked at the code and found a few problems:
The Split function returns a 0-based array, but the index that gets randomly generated goes from 1 (inclusive) to array length (exclusive), meaning it will never return element 0. Also, the \n separated string for nonprimes contains a trailing \n, which means the split function will return an empty string for its final element, which can't be converted to a number by int.Parse.

I don't understand why \n separated strings are used for this in the first place. Why not just create an array of integers? this seems much more efficient. No need to do any splitting or parsing then.