Skip to content

[Suggestion] Random function and system time #67

Open

Description

@TCreopargh

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.

Activity

  1. AlexIIL commented on Feb 19, 2021

    @AlexIIL
    Owner

    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.
  2. AlexIIL commented on Feb 19, 2021

    @AlexIIL
    Owner

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions