Exception in random numbering node


Two questions guys…!

1.How can ask the random node not to generate a list of values that are within the desired range??
min value-0
max value-100
Exception-50 to 60

  1. How to set the minimum and maximum difference between the random generated value??
    min value-0
    max value-100
    min difference between the generated result
    max difference between the generated result

Are there any node available for these,…??


I don’t know of any custom nodes for this but I have some ideas on number 1. Gimme a bit to work some stuff out and I’ll post.

Number 2 I don’t really understand what you’re after but if you expand on it some I may be able to help out.


So this code block takes four inputs - a minimum value, a maximum value, a minimum void, and a maximum void.
It then crates a random list just like the Math.Random node. It then finds the midpoint of the void (half way between the minimum void and the maximum void). It then tests if any of the resulting numbers are between the minimum void and the midpoint of the void, and generates a new random number between the minimum value and the minimum void, and replaces the initial input with that. Numbers which weren’t between the minimum void and the midpoint of the void and tests if they are between the midpoint of the void and the maximum void, and replaces them with a random number between the maximum void and the maximum number.

This maintains some of the initial dispersion of the randomization - that is if a number was randomly in the lower half of the void it is replaced with a number below the void, and if a number is in the upper half of the void it will be replaced by a number above the void.

Inputs =
	{TotalNum, MinNum, MaxNum, MinVoid, MaxVoid};

InitialList =

HalfVoid =
	MinVoid + (MaxVoid - MinVoid) / 2;

VoidedList =
	InitialList > MinVoid && InitialList < HalfVoid?
		InitialList > HalfVoid && InitialList < MaxVoid?


Hi, Jacob thanks for the reply,
Let me explain wat i tried to convey on point 2,
I am trying to create curtain grids with random node, The problem comes in when the grids are generated close to each other
hence reducing the height of the curtain panel, which is practically not possible so I am now looking for a something that allows me to specify the minimum and maximum spacing between the curtain grids.

hope the screen shops helps you understand the question better…!!



I am fairly new to dynamo and these codes are complex to me, but it was clear what these codes are programmed to do as I went through, I am just wondering how to pass the void range if I have a list that isn’t in a range for instance on the above example i need a exception on say 31,46,83and 92


May I ask for a little clarification: are you currently working for Autodesk? Sorry if someone else already asked…


No I am an architect if you are asking by seeing my username, that was probably a default suggestion signup page gave me and no you are first to ask…!!!


create curtain grids with random node

Here is a good article on this topic:


In that case you wouldn’t want to use my code but another programmed for those exact integers. Play around with it and see if you can get there.


Instead of using a Math.Random node to generate the number, you should generate the spacing. Start by dividing the total length by your shortest allowable spacing to get the minimum number of panels. Then use the Math.Random node to generate the spacing between each panel for a list that is as long as the minimum number. Next use a mass addition technique (there is a node for this but I don’t recall where, perhaps clockwork?) to get the location of each panel line along the grid - effectively the results of the math.random node but sorted in order (which is ok based on what you described your situation as). Discard any numbers which are beyond the total length, and proceed on your way.


I almost created it with little coding and more of googling, Except that it is working fine on python console
but not sure how to translate to dynamo version,could you share some tutorials that exp[ains it…?

here is the console code and screen shot :

#create random numbers with exception
minvalue = 0
maxvalue =100
amount= 10
import random
a=[i for i in exception if i in ran]
if a==[]:
  b=[x for x in ran if x not in a]
  c= list(set(ran1 + ran))
  d=[i for i in exception if i in ran1]
  e=[x for x in ran1 if x not in d]
  print ("f",f)
  if int(len(final_ran))!=amount:
    print(amount,"Numbers cannot be created try reducing the value of amount")


Well converted from design script to Python, you’re less new than you think!

I am not a Python guru, but I can see that your Python code needs four inputs - click the plus sign on the left and wire in the inputs so your code knows where to start. :slight_smile:


thank you jacob…!

the problem is dynamo couldn’t import random module, need to know how to import it





As @Yna_Db pointed out you need to import Python modules before you can use them in the Dynamo environment.


A good explanation can be found in this post:


This version is returning a result (but not exactly the one you need). See if it can help to improve yours:


For what it’s worth, this was how I intended the code to work on my end (code block not python).