1
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 5 years have passed since last update.

Pythonでランダムな数列を1行で作る

Last updated at Posted at 2019-01-20

Pythonでランダムな数列を1行のコマンドで作る

ランダムな数列をちょっとほしいときに便利。リスト内包表記を使えば1行で書けます。すぐ忘れそうなので自分用にメモしておきます。
Google Colaboratory(Python3.6)利用。

浮動小数点のランダムな数列を作る

.py
# -10~+10の範囲で浮動小数点のランダムな数列を作る
import random
numlist = [random.uniform(-10,10) for i in range(5)] 
print(numlist)

整数のランダムな数列を作る

.py
# 0~+10の範囲で整数のランダムな数列を作る
import random
numlist = [random.randint(0,10) for i in range(10)]
print(numlist)
1
0
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
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?