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

[Suggestion] Random function and system time #67

Open
TCreopargh opened this issue Feb 19, 2021 · 2 comments
Open

[Suggestion] Random function and system time #67

TCreopargh opened this issue Feb 19, 2021 · 2 comments

Comments

@TCreopargh
Copy link

This will be really helpful in many cases (for example display tips randomly rather than in order)
My thoughts are letting random functions accept a optional seed so it always returns the same value with the same seed, and use system time (rounded to a scale like 10 seconds) so that every time when the game starts, it displays different tips rather than the same order of tips every time.

@AlexIIL
Copy link
Owner

AlexIIL commented Feb 19, 2021

Yes, these sound essential.

I'm probably going to add:

  1. generate_seed(): Generates a new (48 bit integer) seed for use in other functions. (This should be saved in constants).
  2. random(seed): calls random_seeded(seed, 0)
  3. random(seed, index): returns a random number (between 0 and 1) based on both the seed and index - the idea being that you'd keep the seed the same, and pass an ever-increasing index to grab the next value for that seed.
  4. random_int(seed, max): calls random_int(seed, 0, max)
  5. random_int(seed, index, max): returns a random integer between 0 and max-1. Internally this is just min(max - 1, random(seed, index) * max), but it's a lot easier to type this way.

@AlexIIL
Copy link
Owner

AlexIIL commented Feb 19, 2021

I'm not so sure about using the system time directly for this - I'd rather people do:

"constants": {
    "tip_interval": 8.0,
    "tip_seed": "generate_seed()",
    "slideshow_seed": "generate_seed()"
},
"renders": [{
    "image": {
        "parent": "builtin/text",
        "text": "(has_tips() & tip_interval > 0) ? tip(random_int(tip_seed, floor(time / tip_interval), tip_count())) : ''",
        "position_type": "BOTTOM_CENTER",
        "offset_pos": "BOTTOM_CENTER",
        "position": { "x": 0, "y": -10 }
    }
}]

Instead, as then I can generate proper random numbers based off whatever additional information the system has for secure random numbers.

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

2 participants