Random Numbers In Python - In Less Than 4 Minutes

Опубликовано: 15 Январь 2025
на канале: Dubious Code
12
0

Random numbers in python are easy to use. You can get random floats or integers, or even do things like shuffle a list. The key things to know are probably how to set a random seed, how to get a random float, and how to get a random integer. This is a quick, less than 4 minute video to get you on the way to using random.

The key things you probably want to know are

random.seed(10) # set a random seed, to get reproducible values
x = random.random() # get a real value
y = random.randint(0,5) # get a value between 0 and 5 inclusive


All code

Copyright 2021 Google LLC
SPDX-License-Identifier: Apache-2.0
https://www.apache.org/licenses/LICEN...

The Snake image in the thumbnail - by Vecteezy https://www.vecteezy.com/vector-art/4...

dice in thumbnail
https://pixabay.com/vectors/dice-red-...