我这样做是为了测试randint的随机性: >>> from random import randint >>> >>> uniques = [] >>> for i in range(4500): # You can see I was optimistic. ... x = randint(500, 5000) ... if x in uniques: ... raise Exception('We duped %d at iteration number %d' % (x, i)) ... uniques.append(x) ... Traceback (most …
如何使用Swift创建随机颜色函数? import UIKit class ViewController: UIViewController { var randomNumber = arc4random_uniform(20) var randomColor = arc4random() //Color Background randomly func colorBackground() { // TODO: set a random color view.backgroundColor = UIColor.yellow } }