0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Python3: 乱数を発生させる

Posted at

次の記事を参考にしました。
random.randint()とnp.random.randint()の定義の違い

定義

random.randint(a, b)

a以上b以下の整数を1個選んで返します。

np.random.randint(a, b)

a以上b未満の数を1個選んで返します。

上記を確認するプログラム

random01.py
#! /usr/bin/python
# ---------------------------------------------------------------------
import numpy as np
import random

# ---------------------------------------------------------------------
def evaluate01():
    aa = random.randint(1, 7)
    bb = np.random.randint(1,7)
    return aa,bb
# ---------------------------------------------------------------------
for it in range(30):
    rvalue = evaluate01()
    print(rvalue)
# ---------------------------------------------------------------------

実行結果

$ ./random01.py 
(1, 4)
(2, 3)
(2, 3)
(5, 2)
(6, 2)
(1, 5)
(1, 2)
(1, 4)
(7, 2)
(6, 5)
(6, 6)
(3, 1)
(5, 2)
(6, 6)
(4, 1)
(2, 5)
(1, 1)
(6, 1)
(6, 6)
(1, 1)
(1, 2)
(5, 2)
(6, 1)
(7, 2)
(6, 3)
(2, 3)
(6, 6)
(1, 2)
(2, 6)
(4, 1)

確認したバージョン

$ python
Python 3.11.4 (main, Jun  9 2023, 07:59:55) [GCC 12.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> numpy.__version__
'1.24.2'
0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?