Hi all, I stuck on a problem while trying to optimize my dynamo script. This simple method should with every loop add number to random item in a list, but after the process i got sum bigger or smaller than I did loops and adding +1. Here is my code and printscreen. In python idle everything working correct.
Thank you for help in advance.
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
import sys
sys.path.append(r'C:\Program Files (x86)\IronPython 2.7\DLLs')
sys.path.append(r'C:\Program Files (x86)\IronPython 2.7\Lib')
#The inputs to this node will be stored as a list in the IN variables.
looplength = IN[0]
a = IN[1]
import random
def addrandom(n):
n[random.choice(range(len(n)))] += 1
for x in range(IN[0]):
addrandom(a)
OUT = a
EDIT: Python idle was 3.7 Dynamo 2.0 Revit 2019. Looked if random.choice was different in 2.7 but everything seems the same. Looks like a sort of bug for me
.