2013-10-23 165 views
0

我是一個絕對的新手,但有一種感覺,對於知道python的人來說這是一件容易的事情。在當前選擇範圍內選擇一個隨機範圍的曲線

基本上我選擇了一組nurbs曲線,我想要做的是隨機選擇一個指定的範圍。例如,從100條曲線的列表中,或者基本上我選擇的任何一條曲線,給我一個隨機的隨機50回。希望我明確表達了這一點。

到目前爲止我設法得到的所有內容都是在我的選擇中打印一條隨機曲線。

import maya.cmds as m 
import random 
sel = m.ls(sl=True) 
from random import choice 
print choice(sel) 
+0

你應該修改你的崗位上正確顯示的代碼 – yemu

回答

1

random.choice(population)給你一個從​​隨機元素。

random.sample(population, k)爲您提供​​的k元素的樣本。

0

我不知道你的問題的域名,但你可以採取樣品random.sample(瑪雅):

>>> from random import sample 
>>> a = list(range(50)) 
>>> a 
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49] 
>>> sample(a, 10) 
[6, 7, 9, 20, 17, 43, 24, 14, 22, 12]