Python output diffrence between dynamo and python idle

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

.

1 Like

what version of dynamo is this?
what version of python are you running in idle?

1 Like

@2shy It’s working for me

EDIT: Actually it’s not. it gives another sum if disconnect and reconnect the code block with the number 38

Python idle is 3.7 and dynamo is 2.0 Revit 2019, is it any significance?

1 Like

ironPython is 2.7 in Dynamo - so maybe :slight_smile:

1 Like

@2shy I don’t know why but if you change your function as shown below it works.

def addrandom(n):
	randomInd = random.choice(range(len(n)))
	n[randomInd] += 1

1 Like

Well thats a mystery, big thanks.

1 Like