Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing calculated values to random_int does not work as expected #2109

Closed
sagikazarmark opened this issue Sep 12, 2023 · 1 comment
Closed

Comments

@sagikazarmark
Copy link

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.

@mihaitodor
Copy link
Collaborator

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.

@redpanda-data redpanda-data locked and limited conversation to collaborators Sep 12, 2023
@mihaitodor mihaitodor converted this issue into discussion #2110 Sep 12, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants