Grasshopper

algorithmic modeling for Rhino

Hi everyone,

I have a question concerning the picking of a specific item from a list.

I  have two equally long lists, one containing actual data and one containing the chance that the data in the first list is accurate.

The list with chances are all decimals between 0 and 1, added together giving one. They can be seen as a percentage. To illustrate my question, a  very simpple example:

List 1: A, B, C, D

List 2: 0.125, 0.25, 0.5, 0.125

This means a 12.5% chance of A, a 25% chance of B etc.

 

How to 'randomly' pick one item from list 1, taking the probability as given in list 2 in account?

 

Thanks in advance,

Sander

 

Views: 2164

Replies to This Discussion

hi sander,

 

multiply list 2 with 100 or even 1000, feed it into the duplicate data component and create a corresponding number of entries for each entry in list 1 - then randomly pick a entry from this new list (by setting the end of the range to the list length of the new list)

 

best,

chris

 

And if you like it complicated:

sharp!

Hi Chris,

 

Thank you for this simple solution. It works perfect for me! I had however to flip the matrix for both lists in order to get the desired list. At first it created a list in which all list items of the first list were duplicated according all items in the second list.

Also thanks of course for the more complicated solution, though I like to keep things simple this time.

 

Sander

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service