← Back to NumPy Course | Chapter 9: Random Module | Lesson 3 of 6

np.random.randint() का इस्तेमाल

randint आपके specify किए एक range से random whole numbers draw करता है।

In this page:

  1. np.random.randint()
Syntax
python
np.random.randint(low, high, size)

np.random.randint()

np.random.randint(low, high, size) low से लेकर लेकिन high को शामिल किए बिना integers return करता है। अगर आप एक argument दें, इसका मतलब high है और low default से 0 है। किसी भी shape के arrays बनाने के लिए size इस्तेमाल करें।

Note: high value exclusive है, इसलिए randint(1, 7) एक die simulate करता है।

उदाहरण: np.random.randint()

python
import numpy as np

np.random.seed(3)
print(np.random.randint(1, 7, size=10))
print(np.random.randint(0, 100, size=(2, 3)))

# Output:
# [3 1 2 4 1 1 1 6 6 4]
# [[74 41 10]
#  [21 38 96]]
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. यह उम्मीद करना कि high included होगा
  2. यह भूल जाना कि size एक single number return करता है
  3. rand इस्तेमाल करना और int में cast करना
चैप्टर सारांश
  • high exclusive है
  • size output shape control करता है
  • एक argument मतलब high
  • Integers return करता है
🔒

Chapter Quiz — Complete all 6 topics to unlock

0/6 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.