Exception in random numbering exclude a quadrant

i posted in this thread because it is one step further then the solution here;
But this is what i need and what i can’t figure out

Inputs =
	[TotalNum, MinNum, MaxNum, MinVoid, MaxVoid];

InitialList =
	DSCore.Math.Random(
    	MinNum,
    	DSCore.List.OfRepeatedItem(
			MaxNum,
    		TotalNum
		)
	);

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

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

This is an update to dynamo 2.

I need something a bit more complex…and i can’t figure it out…
i have for example 16 circular curves above eachother and i need a rondom point on all of them. But if the first point is at 0.4 then for the next ring i need to exclude that quadrant… so the random number must not be between 0.275 and 0.525 … let’s asume the next input is 0.925… then the next input must not lie between 0.8 and 0.05…

i know this is tricky… but i hope someone can help…

You’d need a for loop built around a logic similar to below. For loop is required as once you change A[n] it would throw off the results for A[n+1]. Doable with design script but I am without my cpu for a bit. Give it a shot on your own and see where you get and I’ll try later (perhaps on my flight to Toronto Tuesday)

//first check if the numbers are too close 
Math.Abs(A[n]-A[n-1]) <0.125 ?
//if true find out of the number is bigger then 0.5 - we don’t want to expend past 1. 
A[n] > 0.5?
//if the number is bigger then 0.5 and smaller then we want to subtract 0.25 (or some other number between 0.25 and 0.5 - you could use a random number generation method here)
A[n] -0.25 : 
//if the number isn’t greater then 0.5 then add 0.25 (or the other number)
A[n] + 0.25 : 
//if the separation between the two values wasn’t less then 0.125 then return the value. 
A[n]  

Hope this helps.

Here’s how you could do the first part, get random numbers ignoring an excluded range. The same idea can be used for the second part of your question. You just have to locate the point and update the excluded range.

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference('DSCoreNodes')
from DSCore import *
#The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN
randMin = IN[0]
randMax = IN[1]
exclMin = IN[2]
exclMax = IN[3]
listLength = IN[4]
out = []

for x in range(listLength):
	r = Math.Random(randMin,randMax)
	while r > exclMin and r < exclMax:
		r = Math.Random(randMin,randMax)
	out.append(r)

#Assign your output to the OUT variable.
OUT = out

image

1 Like

Thanks guys…
this is helpful… i abandoned this idea for this project… it became to slow…so found a workaround

What was the work-around?

i made a list of numbers 3,2,1,4,2,4,3,2 ect… repeated that list enough times… then i a chop and choped it in parts i need… so say the list is 25 long… and that is repeated… but i chop every 17 then i get a pretty random shapes… hope it makes sence…

reed.dyn (327.6 KB)

1 Like

Here’s another option that builds the list for you rather than requiring you to type it out. Using Shuffle ensures that the values are randomized as best as possible and TakeItems lets you specify the number of items you need more easily.
image

1 Like