Grasshopper

algorithmic modeling for Rhino

Selecting a Random Number of Items from a Selection

Hello I need some help with the Random Component in GH. 

I have a series of "Backed" Points in Rhino - some 5162 points (for a map Image for a client). Each of these points is the center to a circle. (7/32") Diameter.

I want to "Randomly" select 50% of the high lighted points and assign it a new 3/16" Diameter Circle. 

I basically want to add a new variable to the field of points I have "baked" out in Rhino. 

For some reason the definition that I have isn't working. When I hover over the outputs I have a list of values but when I turn on the circles and  center points I only have 2 visible. 

What is going on? Any input would be great - thanks. 

Views: 7203

Attachments:

Replies to This Discussion

A better JPG of what I have. 

Attachments:

I suppose your random component have a range of valors from 0 to 1, this is the problem.

0.000 = false

1.000 = true

ok, BUT also

0.499 = true

0.001 = true

meaning in 2581 random generated values, only 2 are EXACTLY zero!

you need to round those values.. so you have only 0 and 1 , false and true.

AND replace your "list item" (at top) with "dispatch" component.

I was wrong :P

You did get only 2 elements because every random generated value was from 0 to 1,

so, since you linked that list of values to INDEX of "list item" component, the output were the first 2 element of the main list extracted a random amount of times (2581 in total), but only the first 2 points...

Sorry for my blabbering...

This is correct.

Attachments:

Thanks for this solution I did get my definition to work - I will give this a shot. I am seeing things here that could answer my next question. I want to be able to select the other points (list) that were not "randomly" selected. 

In you definition I see the "Point" outputs. I am guessing that one of those is a list of other points that were not selected as part of the random assignment. Can I build this and get both sets of data points? 

Or...

Based on what I have - is there a way I can get the other portion of my list? 

Thanks. 

Attachments:

In my definition the list of objects is shuffled randomly, then i simply split in 2 lists ("A" and "B") the main list.

The splitting index is determined by the % you choose.

(In a list of 1000 objects if you want 20% of random items that index will be 200 :D )

Instead of using directly the objects we can work with index; the "Jitter" component give also as output the shuffled indexes at "I".

We can split that list in two indexes lists:

- the list of indexes of randomly piked objects;

- the list of indexes of objects not piked;

(and then optionally sort both of them, if needed)

With indexes you can work with the starting original indexing of your objects,

yes.. this is better.

Tell me if I missed something, my english is not perfect somehow...

Riccardo - thanks! This is a much better solution. 

I have used this and set up two different "Circles" at the end with different Radi. 

However, I am seeing overlap in the two lists - The Random points and the Remainder points share some points and I have two circles on the same point. Do you know why? Or how to keep that from happening? 

This is part of much larger script.... 

Thanks. 

Yes, it should be feasible, just can you please, internalize input data and attach .gh file?

It would be faster this way :)

Sure here you go - let me know if there are other things that you might need. 

Thanks!! 

Attachments:

Does this help??

as David wrote: "(...)If you want a range of numbers without overlaps, it's better to not use the Random component, but instead generate all the numbers using a Range or Series component and then Jitter the list, thus randomizing the order of the values, but not the values themselves."

just shuffle the series of numbers from 1 to 10. Random component actually can only generate series of random numbers but there is very small chance that u will get unique numbers if You need integres.

I think that Jitter is outputting values that repeat in both lists? Would Random and then Jitter work better? 

Duplicate points! That's the problem.

You have a lot of points double (2 in the same place, maybe more?).

I used a "Cull Duplicates" component to fix that.

Yes, it is just wrong to "hope" that creating random indexes wouldn't make duplicates.

Jitter is ok, just it weight less to just shuffle indexes and then proceed to modify the main list with those.

See attached file.

Attachments:

Ricardo Thank you! 

I think that this is a much better solution. 

I also think that there is a way around this by staging the Point input (what is done in Rhino) differently, So I can take advantage of "Select Duplicate" in Rhino. 

If I can avoid having to "Bake" my original point field first, and then "Bake" it twice at the end I should be able to do this and avoid duplicate points..... I will let you know. 

Thanks again for all the help today. 

Hello Riccardo - 

I know it's been a long time, but I wanted to share with you and show you where your help got me. 

I ended up being able to design a custom light grid for a climbing wall in a clients private NYC residence. The grid of points was defined by the image mapper selecting from gradients of gray to get me different sized points (CNC holes for LED's). The final map is of lower Manhattan. 

See the final result. I thought that it would be nice to go full circle so you could see what your guidance helped to get done. 

This was about a year ago - sorry I never got back to posting this to you. 

Happy New Year! 

Attachments:

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service