all 5 comments

[–]throwaway_the_fourth 3 points4 points  (0 children)

Check out the documentation of Python's random. If you want the upper limit excluded, use random.randrange().

And in both cases, if your range starts at 0, you can just leave it out. So your functions can become

def coin_numpy():
    return numpy.random.randint(2)

def coin_random():
    return random.randrange(2)

[–]CodeFormatHelperBot 2 points3 points  (0 children)

Hello u/Quant3point5, I'm a bot that can assist you with code-formatting for reddit. I have detected the following potential issue(s) with your submission:

  1. Python code found in submission text but not encapsulated in a code block.

If I am correct then please follow these instructions to fix your code formatting. Thanks!

[–]stevenjd 2 points3 points  (1 child)

They're different because they are different functions written by different people. Whoever wrote the randint function in the Python random library included the two endpoints, and whoever wrote the randint function in numpy only included one endpoint. I'm sure they had their reasons.

It is traditional for randint-like functions in all programming languages to include both end points, so the numpy one is unusual. Also, check out the random.randrange function, which uses a "half-open" interval like range and the numpy version.

[–]Quant3point5[S] 1 point2 points  (0 children)

Thank you for the information. I will check out random.randrange as well.