mercredi 21 avril 2021

How do I generate predictable events based on date and time? (Random)

I want to generate events based on date and time. It's for a game that has events that are based on date and time. Randomizing would be predictable like getting the next date and time. I couldn't find any information online using the the keywords I could think about. I've here an example use:

DateTimeRandom rand = new DateTimeRandom(5 * 60 * 1000, 30 * 60 * 1000, 30 * 1000, 45 * 1000) // Every 5 to 30 minutes and last for 30 to 45 seconds.

// To get the next event:
LocalDateTime dateTimeNext = rand.nextEvent().

// To get the current event:
if (rand.hasCurrentEvent()) { // Here's the boolean I'm talking about in the title.
    long millis = rand.getCurrentEventDuration(); // Duration in milliseconds.
}

It's ok if time is in nanos.
The class I need DateTimeRandom would have the following paramaters: (long min, long max, long minLength, long maxLength) the parameters are meaning the time that's between every event, and the last two are for the length. I hope this is enough information.




Aucun commentaire:

Enregistrer un commentaire