How to generate different random numbers with random in Python

Posted on: February 3rd, 2023
By: Tadeo Martinez

The “100” is the range, and in range it goes from 0 – 100, unless the first number isn’t specified.

10 in this case is the amount of numbers that will be generated

import random
random.sample(range(100), 10)

# Output

[0,1,2,3,4,5,6,7,8,9]

Here’s the StackOverflow article:
https://stackoverflow.com/questions/9755538/how-do-i-create-a-list-of-random-numbers-without-duplicates

Have any questions or comments? Write them below!


Leave a Reply

Your email address will not be published. Required fields are marked *