I use two architectural programs with visual programming plugins (Grasshopper for Rhino and Dynamo for Revit - for those who know / are interested)
Grasshopper contains a function called "Jitter" that will shuffle the list, however it has an input from 0.0 to 1.0 that controls the degree of shuffling - 0.0 causes no shuffling of 1.0 to produce a complete shuffle.
The second program (Dynamo) does not contain this function. It contains a shuffle module (which contains the initial value), but this is a complete random shuffle.
Ultimately, the goal is to create a series of solid and glazed panels, but produce a small random effect (but avoiding a large accumulation of solid and glazed elements - hence, I want an “easy shuffle”)
I wrote code that will calculate the number of required glazed (True) and solid (False) values, and then evenly distribute True and False values depending on the number of specified elements and percent.
I checked the link to a random module, but I am not familiar with the various distributions as described.
Can someone help or point me in the right direction if an existing function achieves this.
(I changed a bit by adding True False one at a time to make up the correct number of elements in the list - list3 is the final list, list2 contains the repeated module of true folds)
Many thanks
import math
import random
percent = 30
items = 42
def remainder():
remain = items % len(list2)
list3.append(True)
remain -= 1
while remain > 0 :
list3.append(False)
remain -= 1
return list3
list1 = ([True] + [False] * int((100/percent)-1))
list2 = list1 * int(items/(100/percent))
list3 = list2[:]
remainder()
shuffled = random.sample(list3, k = len(list3))
source
share