• Register now to get access to thousands of Tutorials, Leaked content, Hot NSFW and much more. Join us as we build and grow the community.

Advertise Here

Advertise Here

Advertise Here

Random Number Generator in Python

redeagle

Vulnerability Hunter
R Rep
0
0
0
Rep
0
R Vouches
0
0
0
Vouches
0
Posts
118
Likes
159
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 200 XP
Introduction:
This tutorial is on how to create a random number generator in Python.

Imports:
Before we begin, we first need to import the random module...

  1. import

    random

This allows us to use the random modules functions such as 'randrange' and 'randint'.

Random From Zero:
To get a random number from the beginning (zero/0), we can simply call the 'randrange' function from the random module and parse it a final/maximum value as an integer, like so...

  1. print

    (

    random

    .randrange

    (

    100

    )

    )

The above code generates and outputs a random number between 0 and 100.

Random Between:
Or if we need to set a minimum value as well, we can use the 'randint' function. This function generates a random number between parameter 1 (minimum) and parameter 2 (maximum)...

  1. print

    (

    random

    .randint

    (

    20

    ,

    100

    )

    )

The above code generates and outputs a random number between 20 and 100.

 

Create an account or login to comment

You must be a member in order to leave a comment

Create account

Create an account on our community. It's easy!

Log in

Already have an account? Log in here.

452,501

351,517

351,531

Top