List of lists of random values

Hi folks,
I am trying to create a list of lists of random values between 0 and 1. I can easily create ONE list of random entries, but how do I get multiple, where still all values are completely random (without using Python please :wink:, I know there it probably works easily)?
So for this example, how do I get 5 lists of three random numbers between 0 and 1, where all numbers differ (most likely) from each other?

I tried to use the LoopWhile node, but didn’t succeed (maybe I am too stupid, maybe the node is not made for complex operations like this?). Probably it doesn’t work because my boolean continueWhile input doesn’t become a function here, but how would I fix that?

while_loop.dyn (11.6 KB)

Thanks,
GG

no such thing as a stupid question

many ways to do it- try list.chop

1 Like

Wire the ‘count’ slider into a List.OfRepeatedItems node which has another integer input for the number of lists you want.

Typing from memory on a cell phone, but I often use this one liner design script statement when generating such random data sets: Math.RandomList(List.OfRepeatedItem(listSize,numberOfLists));.

Should work for you if you want to keep the values between 0 and 1. If you want different low and high values you can append * (highValue-lowValue) + lowValue or manage the low and high inputs on the other method (just watch the list levels).

2 Likes

That is actually a pretty slick way to approach it! :smiley:
Instead of piling together the list with little chunks, create one big list instead, and chop it down! That works!

1 Like

Thanks a lot Jacob! Your design script solution works. :slight_smile:

I would still love to get my while loop going, as this would work for other use cases then, too. When trying what you suggested, it seems that the attribute of being a function does not travel across nodes. Is this expected or a bug?

Thanks,
GG

S removed. Thanks for the proofreading!

For your function issue, you need to use Function Compose to string nodes together. Once a node has all inputs it cannot be a function, and functions only pass one level unless you use Function Compose as otherwise function passing would be both intolerably slow and unstable.

Be very careful as it is easy to start a loop with no exit here (save after each run, run after each edit). Check the extended node help on the while loop to be sure you have the right types of inputs.

1 Like

You are VERY right with your stability judgement of this option. :joy:
Dynamo died several times on me. :slight_smile:
Now I got it running without it dying, but I don’t get the result I want:

What I am trying to achieve: start with an empty list, and then add as many elements (in this case “1”, later it should be random numbers) until you reach the wanted amount. What am I doing wrong here?
Again, while I don’t need this at the moment, I think it would be super helpful to understand how to build such more complex loops (I am teaching Dynamo a lot currently, and avoiding Python reduces the complexity of my lessons).
Compose.dyn (17.1 KB)
Thanks,
GG

Python and DesignScript are likely easier to teach here, as the use of loops with nodes are typically easier to manage in a custom node environment, and you have to cover functions first which is also hard to include.

That said I recommend using the sample in the extended node help as the base, editing to your needs as applicable.

1 Like

You could just do the following without a “OfRepeatedItems” node. At the end i have added a shuffle node just in case you wanted to shuffle the values to show a different ending.

1 Like

Thanks, Jacob, funny enough, the help explanation is nearly exactly what I was using as a simple example for using the While loop node in my training. :slight_smile: I was hoping to be able to demonstrate it for a more complex task like this one, but if you don’t recommend it, I will switch over to DesignScript or Python instead, as you suggested.

Thanks, Brandon, yes, that is what a chop solution would look like! :slight_smile: I will probably go for another Random node instead of the shuffle, just to ensure complete randomness, but yes, this approach works. :slight_smile:

Not to get too philosophical- but true computer generated randomness is impossible- it’s just an illusion of what we humans thinks looks random

1 Like

2 Likes

Or this one

3 Likes