LoginSignup
1
2

More than 3 years have passed since last update.

乱数一覧

Posted at

乱数

python標準ライブラリのrandomモジュールの関数などを使い乱数を生成できる

必要なライブラリー

import numpy as np

一覧

random.random()
-0以上1未満の浮動小数点数
-size:(1,)

np.random.random()
出力
0.06403549481552051

radnom.uniform(a,b,(x,y))
-任意の範囲の浮動小数点数(a-bの範囲)
-size:(x,y)

np.random.uniform(0,100,(2,2))
#範囲:0-100
#size:(2,2)
出力
array([[54.96297308, 57.53909851],
       [37.99840957, 46.24128482]])

radom.randint(a,b,(x,y))
-任意の範囲の整数型を出力(a-bの範囲)
-size:(x,y)

np.random.randint(0,100,(2,2))
出力
array([[25, 52],
       [54, 92]])

random.normal(loc=a,scale=b,size=(x,y))
-loc:平均
-scale:標準偏差
-size:(x,y)
の浮動小数点数を出力

np.random.normal(0,1,(2,2))
出力
array([[-1.5370704 , -0.47114166],
       [-0.18402346,  1.60225269]])
1
2
0

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
1
2