NightDev Community Forums

Making a command that’s random and only resets by the day

I’m hoping to make a command that pulls from a random pool of options contained in a pastebin, however whatever option the user gets from the pastebin stays the same for that day and changes the next day etc, is this doable?

I’ve been told it may be doable by using fetchurl before the JavaScript to execute the once a day thing if that helps

Hey @Dekufish!

What you’re suggesting will require two commands, one for you that you’d run at the start of every stream to randomly select the output and to store it in the second command.
Another solution would be to give up “pure” randomness and simulate it instead, the advantages will be that you’d need just a single command that anyone could use, and it wouldn’t require you to run a command at the beginning of every stream.

Ultimately it’s up to you to decide how you want to do it: either you’re okay with being bothered to run a command at the beginning of every stream, or you’re willing to give up on “pure” randomness.

Thanks for your reply!

Ideally it’d be simulated however how much perceived randomness can be achieved and are there different ways of doing it?

Just to be sure tho, would either these solutions provide unique randomised or simulated responses for each individual that uses the command?

I have one idea to simulate randomness using the date, but I have to experiment with it to find the best way to do it.
Simulated randomness can be convincing enough, as “pure” randomness itself can sometimes feel not that random.
Note that even “pure” randomness isn’t really random either, it’s based on a seed either way, I’m just suggesting to use a different seed than the one we’d use by default, because it would simplify things for a Nightbot command.

Either of these solutions would give a unique output for the day, and randomize it to a new one the next, the only difference is the type of randomness and the amount of time/effort you’re willing to put into it.

Assuming it’s still doable I’d want to go down the route of simulating it. As a newbie to coding I know it’ll be more challenging but I’m willing to put in the time and effort to figure it out if need be. Any help or insight into how to achieve this would be greatly appreciated.

Sorry I got busy, and I took time to test if my idea to base it on a date could work, and I’m happy to say that it does!
There will be some minor unbalance, but overall it’s gonna be alright, you shouldn’t notice it.

Okay, so let’s get on it, shall we!

$(eval a=`$(urlfetch json https://pastebin.com/raw/XXXXXXXX)`.split(`DIVIDER`); b=`$(time TIMEZONE "MD")`; a[Number.parseInt(b)%a.length])
  1. Replace XXXXXXXX with your Pastebin ID, make sure the expiry date is set to Never.
  2. Replace DIVIDER with the character that divides every options in your Pastebin.
  3. Replace TIMEZONE with yours, you can find the list of supported timezones here.

If you get an error, make sure the Pastebin is Public or Unlisted.

I tested it so it should work first try, but don’t hesitate to ask me questions if there’s something you don’t understand.

1 Like
$(eval a=`$(urlfetch json https://pastebin.com/raw/XXXXXXXX)`.split(`DIVIDER`); b=`$(time TIMEZONE "MD")`; a[(Number.parseInt(b)+$(userid))%(a.length)])

Actually if you want a unique response per day per user you can make a slightly different version that should handle that (Above). The one @Emily gave should give a different response per day but will be the same for all users.

1 Like

Sorry for my late response, you guys are seriously amazing! Thanks so much Emily and potatoeaterlove!

2 Likes

No worries, pleasure is ours!

Just a question tho’, 'cause we’re having a “bet” together: which version of the command were you looking for in the first place, and which version you ended up using? Mine or Potato’s edit?

1 Like

For settling the bet it was potato’s edit I was originally looking for, sorry Emily! However I was likely going to want a command that does what your edit does too, so technically I ended up using both!

2 Likes

Haha, there’s nothing to be sorry for, we were just having a bit of fun, thanks for letting us know, we appreciate it!

1 Like