Passing calculated values to random_int does not work as expected #2110
Replies: 3 comments 3 replies
-
Hey @sagikazarmark that's because the PS: Converting this into a discussion as mentioned in #2026. |
Beta Was this translation helpful? Give feedback.
-
This is actually kind of a bug, or at least a limitation of bloblang. The problem with your mapping is that the argument for We could expand the static evaluation of mappings in order to detect static variables, which in the example you posted would fix things as the arguments would no longer be dynamic. However, that wouldn't solve the greater issue of when those arguments aren't capable of being statically evaluated. The real bug here is that the random number generator is being recreated (and therefore reset) and it's not obvious to you as a mapping author or the config executor why that is happening, or even that it's happening at all. We could potentially maintain a cache of generators that have been created, since by their nature they're meant to be random I think it'd be reasonable to have a shared cache. As a short term work-around you can implement a max the old fashioned way with |
Beta Was this translation helpful? Give feedback.
-
Can't reopen it now that it's been converted so I've opened #2112 |
Beta Was this translation helpful? Give feedback.
-
I'm trying to pick a random element from a list. Here is what I tried so far:
However, this always returns the last item in the list. Checking the output of the call to
random_int
reveals that it always outputs 4.Changing
$regions.length()
to a static number works as expected.Changing the code to the following also works fine:
Not sure if this is a bug or a known limitations. I also wasn't sure how to search the issue tracker for potentially existing issues, my attempts didn't reveal any.
Beta Was this translation helpful? Give feedback.
All reactions