Issue with generating random values in Dynamo

Hi everyone,
I prepared 2 separate scripts using both nodes and using python script to generate random values in Dynamo.The problem I’m facing is that when I run the graph, it generates a random value for once, but when I run it for the second time, I get the same values again and Dynamo does nothing.Can anyone help me figure out how to generate truly random values each time I run the graph in Dynamo? Any suggestions or advice would be greatly appreciated.

Thanks in advance!

@ugur_yavan_61 ,

I like Shuffle… it is just in a codeblock

List.Shuffle(anylist)


KR
Andreas

This is good buy my problem is when you hit the run you get that list which starts with 6,38…If you run it again it will give you exact same list unless you restart the dynamo. How can I solve that problem without restarting dynamo ?

Hello @ugur_yavan_61 …you could try this one here so you dont need restart

1 Like

Thank you for reply but Here also I need to change the seed or restart the dynamo to get another list. Are not there anything like whenever I hit the run it refresh the list like python does. I mean even excel can do that.

Yes it isnt excel :wink: but you could try with a date node and run periodic…

Revit_UaiadumjZX

2 Likes

Thanks a lot, That would work. But I am still curious why it not working when we try to run it manual.

If excel is good for randomize you could probably read from there as well

Actually, It is not about creating random list it is about optimazing a truss. When I run the script one time it sends data to RSA and gets the results but when I try to do it again it gives me “null”. Everytime I need to restart the dynamo.

1 Like

You can’t get any node to refresh unless it’s either tied to an external object changing (ie: all elements of category where a category changes) or an inout value changes.

In the context of Dynamo sandbox, I believe one such listener is a File.FromPath node, which will give you rerun if you modify the file on disc at the end of your run. So read a text document, write out anything to the text document at the end.

I do a LOT of stuff with random, and personally I dislike when the nodes re-execute on each run as it makes debugging impossible as the failing content won’t ever come back, unless your range is controlling the random too much. That input controlling the random is also why I dislike seeded random as it will only return certain values, so the animation posted by @sovitek would actually only give 60 possible values before recycling. The node is necessary for generative design workflows, but it should be used sparingly in my opinion.

But I LOVE Math.RandomList, as I can co from the input to trigger a new value, and I’ll get something unique on every single run.

My personal preference is this in a code block:
‘trigger? Math.RandomList(1)[0] : Math.RandomList(1)[0];`

The trigger input can be a boolean, which would mean you have to toggle it to get a new value, or you can use periodic run and test the time to be equal to ‘antelope’, which will always be true (I hope), but as it will be a new true on each run you’ll get a new value every periodic run.

There are a LOT of ways to utilize random in the context of dynamo overall, but which one you use will usually depend on what you do with the random value. In this case I am assuming one of the inputs to form the truss is using that random value, and so of this doesn’t work out for some reason let us know where the random value is being used and we can help get a better solution.

Hope this helps.

3 Likes

Nice one…and true with seconds it will only random to a limit :wink:

1 Like

Random isn’t something that computers do well.
Randomness 101: LavaRand in Production (cloudflare.com)

2 Likes