0

I am new to programming and am learning Python via Udemy's complete python bootcamp course.

I was working on a project given in the course of making a Tic-Tac-Toe game and got confused.

import random2
def choose_first():
    if random2.randint(0, 1) == 0:
        return 'Player 2'
    else:
        return 'Player 1'

in the above code random2.randint(0, 1) is for commanding python to choose a random value between the range (0,1) but shouldn't the range mentioned in the code be between 0 and 0? since the 1 represents up to the given range, meaning taking numbers before this digit but the code works fine and the value of 0 and 1 is generated.

Why is that? What am i not understanding?

Thank you

Akshat Bhardwaj
  • 73
  • 1
  • 1
  • 3
  • Do you have to use random2 instead of random? In which case the definition is [`a <= N <= b`](https://docs.python.org/2/library/random.html#random.randint). – Arne Feb 15 '18 at 09:20
  • 1
    documentation for Python 2 [`randint`](https://docs.python.org/2/library/random.html#random.randint) : *"Return a random integer N such that a <= N <= b."* – UnholySheep Feb 15 '18 at 09:21
  • 1
    random.randint(a, b) is for choosing a random integer between values a and b, random.range() doesnt work to choose between floating point a and b, random.uniform(a, b) – user1779646 Feb 15 '18 at 09:44

0 Answers0