В стандартном модуле random есть две очень похожие функции
random.randint()
random.randrange()
Обе возвращают случайное значение из указанного диапазона
>>> random.randint(10, 20)
12
>>> random.randrange(10, 20)
17
В чем же отличие?
Дело в том что у randrange() есть третий параметр step.
randint() действительно возвращает случайное число из указанного диапазона.
randrange() на первый взгляд делает тоже самое если передать также два параметра.
Но есть указать еще и step то наш диапазон усложняется, то есть в него попадёт не полный ряд значений.
Например, я хочу получить случайное значение из диапазона но только чётное число. Тогда достаточно сделать так:
>>> randrange(10, 20, 2)
16
Таким образом получается что randint это частный случай randrange без указания параметра step.
Еще одно важное отличие в том, что randint() включает в диапазон второе значение а randrange() нет. То есть выражение randrange(10, 20) никогда не вернёт 20, а randint(10, 20) вернёт.
#tricks#basic
➡️New build available for Xiaomi POCO M3/Redmi 9T (chime)
👤 by
ℹ️ Version: 12
📆 Build date: November 25, 2022 01:10
📂 File size: 1.66 GB
⬇️ Download now
#chime#pixelexperience
➡️New build available for Xiaomi POCO M3/Redmi 9T (chime)
👤 by
ℹ️ Version: 12
📆 Build date: November 20, 2022 11:41
📂 File size: 1.66 GB
⬇️ Download now
#chime#pixelexperience
🪐 One of the largest samples of fast radio bursts (FRBs) ever recorded comes from the Canadian Hydrogen Intensity Mapping Experiment (CHIME), which has detected thousands of these brief, mysterious flashes from all directions across the sky. Each FRB is a burst of radio energy that lasts just milliseconds, often releasing more power than our Sun emits in days, and their unpredictable appearances continue to challenge scientists searching for their true origins. ✨
#FRB⚡#CHIME⚡#astronomy⚡#nasa⚡#galaxy⚡#stars⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels