The new NodeBox forum is live! Everything from support.nodebox.net moved here: sign in with the same email to pick up your old posts. Something not working? Write to forum-support@nodebox.net.

Show your WorkFrom the old forum

Take Sample

No replies yet

  1. Today's new node: take_sample

    Take_sample takes an evenly distributed subset - or superset - from a list. The list can be anything: points, shapes, data table rows, numbers, whatever. If the list is shuffled you will get a random sample. If it sorted you'll get an even sample across whatever the list was sorted by.

    Take_sample takes four parameters:

    • The list
    • Amount. This can be more than the number of items in the list.
    • Allow duplicates. If checked you are guaranteed to get the amount you asked for; if this is more than the number of items in the list, you will get a sample of duplicates to make up the difference. If not checked you will never get more than the number of items in the list.
    • Take all. If checked, the previous two settings will be ignored and you will get the whole list, just as if you had never added the take_sample node.

    I developed this node when taking a random sample of fonts from my system, but you could use it for many other things. If given a shuffled list it will provide a random sample (though you could do the same thing with a slice node). It's really more useful when given an ordered list. Given a ordered list of cities and average temperatures you could use it to select a subset ranging from cold to hot.

    The demo (attached) shows a shuffled grid of 64 stars of varying sizes. The goal is to pick nine of these at random but with steadily increasing sizes. I show arrows leading from the smallest to the largest star. You can keep changing the seed on the shuffle1 node to get different arrangements of stars. Each selection will be random but each of the nine stars picked will be bigger than the previous one.

    I will also find this useful when debugging. When I am working on something that acts on a large list of items I will typically start by picking just one item and, then, when that is working, gradually add more. Often I will want these items to be sorted in some way and will want a sample cross section to test. Take_sample will make this easier.

    Simple but, I hope, useful.

    Copy link

Know something that helps?

Sign in with your email address to reply. No password needed.

Sign in to reply