coding-coworking-club / python-spring-2021

ccClub Python Spring 2021
https://www.ccclub.io/course/2021Spring
23 stars 6 forks source link

[Homework 補交區#] 小華的抽籤程式 #498

Closed andrewyao67 closed 3 years ago

andrewyao67 commented 3 years ago

提交連結

https://judge.ccclub.io/status/b6956ceb115f2a62274c9972d9c0eaf4

程式碼

import random
a = random.randint(1,1000000000)
b = random.randint(1,1000000000)
c = random.randint(1,10000)
def randomseed(a,b,c,rr):
    return (a*rr+b)%c
d = list(map(int,input().split()))
rand = [d[0]]
for i in range(d[1]):
    rand.append(randomseed(a,b,c,int(rand[i])))
    print(rand[i+1])

錯誤訊息

問題描述

a,b,c每次出來都會不一樣答案就會變,是要不管執行幾次,機率都相同的那種嗎?

TJ72 commented 3 years ago

請參考 Python 的亂數官方文件,裡面的 rand.seed()的用法與介紹是完成這題的關鍵

andrewyao67 commented 3 years ago

謝謝助教!