Custom Loading Screen

Custom Loading Screen

3M Downloads

[Suggestion] Random function and system time

TCreopargh opened this issue ยท 2 comments

commented

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.

commented

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.
commented

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.