Exception in random numbering node

#1

Two questions guys…!

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

1. How to set the minimum and maximum difference between the random generated value??
Example
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,…??

#2

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.

#3

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 =
Math.Random(
MinNum,
List.OfRepeatedItem(
MaxNum,
TotalNum
)
);

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

VoidedList =
InitialList > MinVoid && InitialList < HalfVoid?
Math.Random(
MinNum,
MinVoid
):
InitialList > HalfVoid && InitialList < MaxVoid?
Math.Random(
MaxVoid,
MaxNum
):
InitialList;``````

#5

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…!!

!

#6

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

#7

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

#8

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…!!!

#9

create curtain grids with random node

Here is a good article on this topic:

#10

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.

#11

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.

#12

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
exception=[1,6,43,67,82,93]
import random
ran=random.sample(range(minvalue,maxvalue),amount)
print("ran",ran)
a=[i for i in exception if i in ran]
len_a=len(a)
print("a",a)
if a==[]:
final_ran=ran
else:
b=[x for x in ran if x not in a]
print("b",b)
ran1=ran=random.sample(range(minvalue,maxvalue),(maxvalue-minvalue))
print("ran1",ran1)
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]
f=b+e
f=list(set(f))
print ("f",f)
final_ran=f[:amount]
print(final_ran)
if int(len(final_ran))!=amount:
print(amount,"Numbers cannot be created try reducing the value of amount")
``````

#13

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.

#14

thank you jacob…!

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

#15

#16

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

#17

A good explanation can be found in this post:

#19

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

#20

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