Random Different Numbers

Hi,
I want to create a random numbered list of 3 items valued between 0 and 24.
And I need these numbers all to be different from each other.
I couldn’t create logic (also the condition) and I need your thoughts on this.

In this example, I don’t want a list as I circled.

Thanks,

Create a range of numbers, shuffle them and pull the first x amount of numbers that you need :slight_smile:

Jonathan thanks for the answer but I cannot use shuffle as an (integer) input for Refinery.

I’m trying to minimize the material cost between 3 cuboids and while minimizing the value those 2 cuboids uses the same point in order to minimize the distance. That’s why I’m trying to attain them to different points.

1 Like

But you could use the amount to push and pull from the shuffle :slight_smile:

1 Like

Ok I get the shuffled list and set amount to 3 to pull the first selected 3 numbers. But how Refinery will create different population if it’s input is a static number as it’s 3. When it’s “sequence random numbers”,refinery is able to try between other seeds.
I’m sorry if I didn’t understand you :frowning:

I’ll try and illustrate tomorrow :slight_smile: I’m not at a computer before tomorrow eve :slight_smile:

1 Like

Any ‘random’ value or shuffle method will not reproduce when you go to take the day out of Refinery, and will throw off the entire optimization run. As such you won’t be able to optimize anything. Instead build the list of values, or work with list permutations or other data method which will get a consistent value.

Knowing it’s also just three numbers and there is a small range, three number sliders from 0-24 is likely your best bet. Add in some logic that asks “if number 2 == number 1, divide by 2 and round up” and then “if number 3 is equal to number 1 divide by 3 round up, then check if number 3 equals number 2 and divide and round again if so.”

I may be able to help guide you more if you provide more data on what it is you are using the numbers for, showing the relevant parts of the graph and what they are controlling in the end.

1 Like

Without testing (not behind a computer atm) this should work (returns a list with 3 unique random numbers):

import random
list_with_nums = IN[0]
amount = IN[1]
OUT = random.sample(list_with_nums, amount)
1 Like

Jacob you’re right though but I couldn’t find any way to define an output otherwise. I’m trying to optimize the adjacency between three cuboids.

The reason I randomize the location is to make Refinery find alternative placements and tell me which suit better due to the rules I defined by the Conditional. At least I hoped so. If cubes are in the right place it won’t have a color. Otherwise, they will be red and I’ll choose the right option amongst them. That’s my plan but it sure is not an optimization path. How can I improve it?

Your screen capture lacks any detail for me to weigh in on your current solution. Try using a workspace export after zooming into one node so it’s completely visible instead.
image

Generally speaking, there are many options besides random. I usually recommend utilizing number sliders and some post slider logic to shift any duplicate values (do them one at a time). List permutations also work, but can make optimization difficult for Refinery.

It also helps to have something static to compare to - that is find the optimum for your first piece, or hard code a common sense placement for it, then use Refinery to locate pieces 2 to N after that. Otherwise refinery will often shift piece 1 and maintain the relationship for pieces 2 to N the same distance.

Jacob I’m so sorry :see_no_evil::speak_no_evil: I did not check it after…
Here is the graph by the way.

How can I put a system where the cuboids start to place themselves other than this method? You are right that random placement will not remember the seed next time I open the graph.

Hi @JJUlkins , I think @Jonathan.Olesen’s solution will work but replace List.Shuffle with Manage.RandomiseOrder node (Lunchbox package) so you can still have the “seed” as an input slider which can be run in Refinery. Had the same issue yesterday :slight_smile:

2 Likes

Personally I don’t use a random method at all. Such techniques will cause Refinery to be unable to optimization as there is no correlation between seed 1 and seed 2.

Instead use number sliders to shift the distances and directions rather than building a list of all possible points, then move objects from the origin.

Alternatively you can look into list permutations which at least maintain some similarities between permutation 1 and 2. Eventually these do fall off a cliff with no correlation at permutation (n-x)!. As a result this method may not always find a global optimum, but you generally finds a local optimum or two in most decent runs. Limiting your lists to 12 items or less certainly helps in that front.

Note that in either case of list alteration (random or permutations) you are exploring contents in factorial design space, so the numbers will rapidly eclipse the limit of integer sliders in Dynamo (happens in design spaces as small as 13 items long), but with some creative python work you can circumvent that limit.

1 Like

@jacob.small thanks!! I actually chose to use number sliders for my main functioning graph in order to use in Refinery. I haven’t discovered permutations yet, but I’m on it :wink:
For now, I’ll accept @archjahzzy’s solution as it solves my problem at the mock-up model. But I’ll try to see how can I use the permutation to create a set of rules between my cuboids to find their places at the main model. I’d appreciate if you know and can share an example topic at the forum. I’d like to analyze the graph.

Thank you all for your answers!