Keep Talking and Nobody Explodes

Keep Talking and Nobody Explodes

Prime Checker
3 条留言
eXish  [作者] 2019 年 12 月 30 日 上午 11:45 
Thanks for letting me know
Dark Heresy 2019 年 12 月 30 日 上午 10:25 
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 2019 年 12 月 30 日 上午 10:11 
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.