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

Answers will partially repeat every ~110 days #78

Closed
escalonn opened this issue Apr 20, 2022 · 4 comments
Closed

Answers will partially repeat every ~110 days #78

escalonn opened this issue Apr 20, 2022 · 4 comments

Comments

@escalonn
Copy link

escalonn commented Apr 20, 2022

Due to the specific PRNG method of selecting each day's answer, on any given day, about half the time, the same answer will be chosen as 110 days previous. For example, today's (4/20's) answer would have also been the answer for 12/31. Same for 4/19 and 12/30, and 4/18 and 12/29. 4/17 and 12/28 are different: but only off by one from each other in the sorted order of countries.

Depending on your design goals, this might not even be an issue, who's going to notice. But you don't get any duplicates in a given interval of 110 answers - or at least we haven't in the last 110 days, which would be extremely unlikely with true randomness. Maybe that's a good thing though? I generated a few thousand and it looks like all the countries do get hit with equal probability in the long run, at least.

This kind of issue is pretty common to PRNGs like this, maybe you can get better behavior just by using a prime number instead of what you're using now. [nah, mistaken.] Or just change techniques entirely, maybe just use Math.random?

If you run something like this, put the output in both panels of a difftool, and delete the first 110 lines from one of them, you'll see what I mean. Probably. Difftools are stubborn sometimes

const date = new Date();
for (let i = 0; i < 200; i++) {
  const dateStr = date.toLocaleDateString("en-CA");
  const key = generateKeyNew(countryData, dateStr);
  console.log(countryData[key].properties.NAME);
  date.setDate(date.getDate() - 1);
}

Thanks for the fun game, just got my average down to 4 today. Got curious because there hadn't been a single duplicate yet. Anyway close/delete this if it's working as intended or near enough. I guess I'm just curious if you meant for it to work this way to intentionally avoid recent duplicates.

@epixian
Copy link

epixian commented May 14, 2022

Today's country is a good example of why I think the selection should be more random. Hunting around in the Pacific is no joke, took me 7 honest guesses to locate today's mystery country. I play against my brother, who today avoided wasting guesses on recent mystery countries (before I started playing with him) and got it in 3. If the selection process were more random, knowing the recent countries wouldn't be a viable strategy.

@the-abe-train
Copy link
Owner

Super late in responding to this, but I have an update.

For starters, using Math.random isn't an option for this game because everyone needs to have a the same mystery country for the day, and it cannot change when you refresh the page.

However, the mystery countries have indeed begun to repeat, so I just updated the code with a line that will "reshuffle" the answers at the end of the month. The reason that it cannot go into effect right away is because, since the game is entirely client-side rendered, players' browsers cache the js files, and so not every player receives updates at the same time. With just over 2 weeks for the change to go into effect, I believe that all players' browsers will get the new code before the reshuffle happens.

@epixian
Copy link

epixian commented Dec 16, 2022

The country selection is only as random as the length of countries allows and periodic updates to an env value.

Suggest moving to a more-random RNG instead, try: https://github.com/bryc/code/blob/master/jshash/PRNGs.md#mulberry32

@epixian
Copy link

epixian commented Dec 16, 2022

Added a quick PR: #149

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

3 participants