# Issue with generating random values in Dynamo

**URL:** <https://forum.dynamobim.com/t/issue-with-generating-random-values-in-dynamo/87778>\
**Category:** Lists-Logic\
**Tags:** python, dynamo\
**Created:** [March 24, 2023, 10:54am UTC](https://forum.dynamobim.com/t/issue-with-generating-random-values-in-dynamo/87778 "2023-03-24T10:54:55Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![ugur\_yavan\_61](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/ugur_yavan_61/32/160009_2.png) [@ugur\_yavan\_61](https://forum.dynamobim.com/u/ugur_yavan_61)\
**Post date:** [March 24, 2023, 10:54am UTC](https://forum.dynamobim.com/t/issue-with-generating-random-values-in-dynamo/87778/1 "2023-03-24T10:54:55Z")

</div>

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.

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/c/f/cfb6944cc0b3598b025962b38ab180404d4b7ebd.png)

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![Draxl\_Andreas](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/draxl_andreas/32/145744_2.png) [@Draxl\_Andreas](https://forum.dynamobim.com/u/Draxl_Andreas)\
**Post date:** [March 24, 2023, 10:57am UTC](https://forum.dynamobim.com/t/issue-with-generating-random-values-in-dynamo/87778/2 "2023-03-24T10:57:39Z")

</div>

@ugur_yavan_61 ,

I like Shuffle… it is just in a codeblock

```auto
List.Shuffle(anylist)

```

 ![grafik](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/0/e/0eef77989283ed7f140eed3a9dbc7d5750115cd6.png)  
KR  
Andreas

---

<div class="post-metadata">

**Author:** ![ugur\_yavan\_61](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/ugur_yavan_61/32/160009_2.png) [@ugur\_yavan\_61](https://forum.dynamobim.com/u/ugur_yavan_61)\
**Post date:** [March 24, 2023, 11:49am UTC](https://forum.dynamobim.com/t/issue-with-generating-random-values-in-dynamo/87778/3 "2023-03-24T11:49:30Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![sovitek](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/sovitek/32/116237_2.png) [@sovitek](https://forum.dynamobim.com/u/sovitek)\
**Post date:** [March 24, 2023, 11:52am UTC](https://forum.dynamobim.com/t/issue-with-generating-random-values-in-dynamo/87778/4 "2023-03-24T11:52:37Z")

</div>

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

 ![Capture](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/a/c/ac2d6a6e63c8637ceaf228c6136b11878a58baf5.png)

---

<div class="post-metadata">

**Author:** ![ugur\_yavan\_61](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/ugur_yavan_61/32/160009_2.png) [@ugur\_yavan\_61](https://forum.dynamobim.com/u/ugur_yavan_61)\
**Post date:** [March 24, 2023, 12:07pm UTC](https://forum.dynamobim.com/t/issue-with-generating-random-values-in-dynamo/87778/5 "2023-03-24T12:07:51Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sovitek](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/sovitek/32/116237_2.png) [@sovitek](https://forum.dynamobim.com/u/sovitek)\
**Post date:** [March 24, 2023, 12:34pm UTC](https://forum.dynamobim.com/t/issue-with-generating-random-values-in-dynamo/87778/6 "2023-03-24T12:34:28Z")

</div>

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

![Revit_UaiadumjZX](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/6/e/6e8b554dcadff2d8c933c131b12ebb2cf4558a8b.gif)

---

<div class="post-metadata">

**Author:** ![ugur\_yavan\_61](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/ugur_yavan_61/32/160009_2.png) [@ugur\_yavan\_61](https://forum.dynamobim.com/u/ugur_yavan_61)\
**Post date:** [March 24, 2023, 1:01pm UTC](https://forum.dynamobim.com/t/issue-with-generating-random-values-in-dynamo/87778/7 "2023-03-24T13:01:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sovitek](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/sovitek/32/116237_2.png) [@sovitek](https://forum.dynamobim.com/u/sovitek)\
**Post date:** [March 24, 2023, 1:04pm UTC](https://forum.dynamobim.com/t/issue-with-generating-random-values-in-dynamo/87778/8 "2023-03-24T13:04:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ugur\_yavan\_61](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/ugur_yavan_61/32/160009_2.png) [@ugur\_yavan\_61](https://forum.dynamobim.com/u/ugur_yavan_61)\
**Post date:** [March 24, 2023, 1:08pm UTC](https://forum.dynamobim.com/t/issue-with-generating-random-values-in-dynamo/87778/9 "2023-03-24T13:08:14Z")

</div>

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.

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/b/8/b831691767ae8f547a621a30bac0eb3105a3a5e8.png)

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [March 24, 2023, 1:14pm UTC](https://forum.dynamobim.com/t/issue-with-generating-random-values-in-dynamo/87778/10 "2023-03-24T13:14:19Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sovitek](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/sovitek/32/116237_2.png) [@sovitek](https://forum.dynamobim.com/u/sovitek)\
**Post date:** [March 24, 2023, 1:16pm UTC](https://forum.dynamobim.com/t/issue-with-generating-random-values-in-dynamo/87778/11 "2023-03-24T13:16:54Z")

</div>

> [@jacob.small](#):
>
> ‘trigger? Math.RandomList(1)[0] : Math.RandomList(1)[0];`

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

---

<div class="post-metadata">

**Author:** ![aaronrumple](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/aaronrumple/32/195292_2.png) [@aaronrumple](https://forum.dynamobim.com/u/aaronrumple)\
**Post date:** [March 24, 2023, 1:27pm UTC](https://forum.dynamobim.com/t/issue-with-generating-random-values-in-dynamo/87778/12 "2023-03-24T13:27:36Z")

</div>

Random isn’t something that computers do well.  
[Randomness 101: LavaRand in Production (cloudflare.com)](https://blog.cloudflare.com/randomness-101-lavarand-in-production/)
