Sam F
Sam F

Reputation: 29

Using random how do you generate pseudorandom numbers with no decimals?

Using the current code that is below this code will create a random number with a massive amount of decimals. Example: 8.71763761465. I'm guessing that there is a way to generate numbers with no decimal, I just don't know how. How do you generate numbers without massive amounts of decimals? Thank you.

import random
randint = random.uniform(1, 10)
print (randint)

Upvotes: 0

Views: 270

Answers (1)

Athena
Athena

Reputation: 3228

Why not just cast it to an int?

import random
randint = int(random.uniform(1, 10))
print(randint)

Or, more appropriately, just use randint:

import random
randint = random.randint(1, 10)
print (randint)

Upvotes: 1

Related Questions