Grid Sage Forums

Grid Sage Forums

  • November 21, 2024, 05:44:32 PM
  • Welcome, Guest
Please login or register.

Login with username, password and session length
Advanced search  

News:

LINKS: Website | Steam | Wiki

Author Topic: RNG  (Read 1751 times)

Joshua

  • Sigix
  • ****
  • Bug Hunter Weekly Seed Participant Shared a Confirmed Combat Win Shared a Confirmed Stealth Win
  • Posts: 319
    • View Profile
RNG
« on: February 14, 2018, 06:00:32 AM »

I don't know if this is a bug or not, but I've failed at 50%, 60%, 70% hacks enough times in a row (sometimes 5 or 6 times in a row at the same terminal) often enough that I've wondered if the RNG is biased towards failure. I thought I would mention it since it is easier for you to confirm/deny than for me to check by collecting statistics. Of course sometimes I also get lucky at low chance hacks a ridiculous number of times in a row, so this could just be normal random variation.

The naive method I used to use (random() % 100) is biased towards lower numbers because 2^8, 2^16, 2^32 aren't evenly divisible by 100. It's fairer to mask and reroll - probably you already know this, but mentioning it just in case:

Code: [Select]
int roll;
do {
  roll = (random() & 0x7f);
} while (roll > 99); // assuming you want 0..99

Edited to add: To explain a little more - masking with &0x7f (assuming random() itself is fair) will produce output 0..127. Taking the remainder when dividing by 100 will map 0..50 and 100..127 to 0..50, meaning the chance of getting a number less than or equal to 50 is (51 + 28) / 128 = almost 62%, almost a 25% difference from the intended success/failure rates.
« Last Edit: February 14, 2018, 06:11:05 AM by Joshua »
Logged

Kyzrati

  • Administrator
  • True Cogmind
  • *****
  • Posts: 4477
    • View Profile
    • Cogmind
Re: RNG
« Reply #1 on: February 14, 2018, 06:15:00 AM »

The statistics are fine, I've checked the long-term distribution several times before and it's correct, that's just the way the RNG ends up rolling. I don't even handle RNG stuff on my own because I'm not nearly that technically advanced :P. I just use a publicly available and widely used Mersenne Twister algorithm written by smart people :P

That said, for a while I've had on the near-term list an intended change to machine RNG internals to see if an idea I have impacts anything on the player side. Can't talk about it in detail, though.
Logged
Josh Ge, Developer - Dev Blog | @GridSageGames | Patreon

DDarkray

  • Cyborg
  • ***
  • Shared a Confirmed Combat Win Shared a Confirmed Stealth Win Wiki Contributor Bug Hunter Weekly Seed Participant
  • Posts: 206
    • View Profile
Re: RNG
« Reply #2 on: February 14, 2018, 09:10:20 AM »

I read an article about a professor who asked each student to flip a hundred coins and then record their result for submission. Turns out, the professor was able to accurately guess who did the homework and who made up the coin flip result. His secret? The one who actually did the homework usually has a long streak of heads or tails.

The point is that having a long streak of failure does happen. You probably don't remember the number of times you had a streak of success, so when you suddenly got a streak of failures, it's easy to blame on the RNG system.  :P
Logged

Kyzrati

  • Administrator
  • True Cogmind
  • *****
  • Posts: 4477
    • View Profile
    • Cogmind
Re: RNG
« Reply #3 on: February 14, 2018, 05:56:03 PM »

It's true, people are generally bad at this, and the issue is exacerbated by the fact that specifically with regard to hacking the chances are listed so clearly, and a player will quickly build up expectations looking at the first attempt or two. There are definitely many streaks with positive outcomes as well.

I doubt the change I plan to make will have any noticeable effect (statistically it shouldn't), but I'll do it anyway and have more to say on this in the future.
Logged
Josh Ge, Developer - Dev Blog | @GridSageGames | Patreon

Kyzrati

  • Administrator
  • True Cogmind
  • *****
  • Posts: 4477
    • View Profile
    • Cogmind
Re: RNG
« Reply #4 on: April 29, 2018, 08:17:56 AM »

Haha, I went to make the change just now only to find that I had already gone through with plans to do this just before the Beta 1 release, so for the past year we've actually had a dedicated RNG specifically for hacking. And it's a high-quality RNG, too, so really this is pure variance... Nothing the can be done about it beyond this aside from actually fiddling with the results to make it not fail (or succeed!!!) so much in a row, but that's not really a great road to go down.
Logged
Josh Ge, Developer - Dev Blog | @GridSageGames | Patreon

b_sen

  • Derelict
  • **
  • Shared a Confirmed Stealth Win
  • Posts: 66
    • View Profile
Re: RNG
« Reply #5 on: April 29, 2018, 09:45:32 AM »

Haha, I went to make the change just now only to find that I had already gone through with plans to do this just before the Beta 1 release, so for the past year we've actually had a dedicated RNG specifically for hacking. And it's a high-quality RNG, too, so really this is pure variance... Nothing the can be done about it beyond this aside from actually fiddling with the results to make it not fail (or succeed!!!) so much in a row, but that's not really a great road to go down.

Haha, good job, past Kyzrati version.  (Except for logging that this was already done.)  XD

Yeah, fiddling with the results would be the opposite of helpful here.  Might be my knowledge of probability speaking, but I like knowing that the probabilities are always as stated and I can calculate streak chances on my own using that.
Logged

Kyzrati

  • Administrator
  • True Cogmind
  • *****
  • Posts: 4477
    • View Profile
    • Cogmind
Re: RNG
« Reply #6 on: April 29, 2018, 05:23:58 PM »

Hey I did log it! I log everything, but after a year had gone by (and this was a secret update because I didn't want people to know about it, so it was never discussed publicly!) I completely forgot I'd already done it and added it onto the future TODO list again not too long ago. It got added back on because the exact same kind of occasional streaks were happening and Mojo was talking about it. But my notes in the code that I found last night did state that according to my tests there would be no noticeable change. So I guess that's settled...
Logged
Josh Ge, Developer - Dev Blog | @GridSageGames | Patreon

b_sen

  • Derelict
  • **
  • Shared a Confirmed Stealth Win
  • Posts: 66
    • View Profile
Re: RNG
« Reply #7 on: April 29, 2018, 06:12:36 PM »

Okay, okay, it was system corruption instead of a logging failure. :P XD
Logged