You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to pick a random element from a list. Here is what I tried so far:
let regions = ["us-east-1", "us-west-1", "us-east-2", "us-west-2"]
let region = $regions.index(random_int(max: $regions.length()))
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:
let regions = ["us-east-1", "us-west-1", "us-east-2", "us-west-2"]
let region = $regions.index(random_int() % $regions.length())
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.
The text was updated successfully, but these errors were encountered:
Hey @sagikazarmark that's because the random_int() function has a seed parameter which is set to 0 by default (docs here). Try random_int(seed:timestamp_unix_nano(), max: $regions.length()).
PS: Converting this into a discussion as mentioned in #2026.
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.
The text was updated successfully, but these errors were encountered: