python程式設計 隨機數列表生成座標

2021-10-03 06:29:22 字數 1518 閱讀 2165

場景

1.使用乙個類生成隨機數

2.可以自定義隨機數的個數和隨機數的範圍

3.將生成的隨機數隨機組合生成座標然後列印

import random

class

int_number

:"""可以設定生成數字的個數,可設定生成的數值的範圍。

執行時還可以調整每批生成數字的個數"""

test_list =

def__init__

(self, area, count=10)

: self._area = area

self._count = count

deforigin

(self)

: test_list =

for i in

range

(self._count):0

, self._area)

) flag =

'no'

while flag ==

'no'

:# for x in range(0, len(test_list)):

# for y in range(0, len(test_list)):

# print((test_list[x], test_list[y]))

test_set =

set(

(test_list[x]

, test_list[y]

)for x in

range(0

,len

(test_list)

)for y in

range(0

,len

(test_list)))

print

(test_set)

flag =

input

('現在退出嗎?(yes/no)'

)if flag ==

'yes'

:break

elif flag ==

'no'

:continue

else

: flag =

input

('wrong input, try again:(yes/no)'

)def

operation()

: count =

int(

input

('整數個數為: '))

area =

int(

input

('整數的範圍是0~?: '))

int_number(area, count)

.origin(

)if __name__ ==

'__main__'

: int_number.operation(

)

Python 生成一組隨機數列表

一.最直接的方式 用numpy.random模組來生成隨機數組 1 np.random.rand 用於生成 0.0,1.0 之間的隨機浮點數,當沒有引數時,返回乙個隨機浮點數,當有乙個引數時,返回該引數長度大小的一維隨機浮點數陣列,引數建議是整數型,因為未來版本的numpy可能不支援非整形引數。im...

Python 生成一組隨機數列表(有放回)

一.最直接的方式 用numpy.random模組來生成隨機數組 1 np.random.rand 用於生成 0.0,1.0 之間的隨機浮點數,當沒有引數時,返回乙個隨機浮點數,當有乙個引數時,返回該引數長度大小的一維隨機浮點數陣列,引數建議是整數型,因為未來版本的numpy可能不支援非整形引數。im...

python隨機數生成

python中的random模組用於生成隨機數。下面介紹一下random模組中最常用的幾個函式。random.random random.random 用於生成乙個0到1的隨機符點數 0 n 1.0 random.uniform random.uniform的函式原型為 random.uniform...