Skip to content
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

Feature: Random Number Generator #674

Open
barum opened this issue Mar 21, 2023 · 2 comments
Open

Feature: Random Number Generator #674

barum opened this issue Mar 21, 2023 · 2 comments

Comments

@barum
Copy link

barum commented Mar 21, 2023

What would it take to add a std.rand to the standard library?
It seems like a very useful function.

@sbarzowski
Copy link
Collaborator

We go to great lengths to make the output deterministic and well-defined (so you can run a different implementation of Jsonnet on any platform and get byte-for-byte the same output).

I would be open to adding pseudo-random numbers if their definition is laid down precisely in the spec (and seed is provided explicitly).

@sbarzowski sbarzowski reopened this Apr 5, 2023
@mkmik
Copy link

mkmik commented Jul 18, 2023

FWIW when I need a "random" number generally resort to hashing some value and deriving a value from that hash:

Example from real use case:

   // Deterministic skewed interval
  local interval = std.format(
    '%sm',
    (
      60 * 26 -
      (2 * std.parseHex(std.slice(std.md5(clusterName), 0, 2, 1)))
    )
  );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants