## Random or Pseudorandom?

General feedback and discussion of the game.

Moderators: Forum Moderators, Developers

HomerJ
Posts: 812
Joined: April 25th, 2008, 1:22 pm
Location: Hannover, Germany

### Re: Random or Pseudorandom?

Max wrote:
Insinuator wrote:However the study and (maybe) correction of this problem isn't nearly as complicated as the problem itself. If there IS a problem with the RNG, however miniscule, it stems from the use of rand(), a basic pseudorandom number generator built into the language for simplicity.
wesnoth doesn't use rand().

Dave wrote: Note that to generate random numbers, Wesnoth basically just uses rand().

Greetz
HomerJ
Six years without a signature!

Max
Posts: 1449
Joined: April 13th, 2008, 12:41 am

### Re: Random or Pseudorandom?

wesnoth uses this approach:
http://en.wikipedia.org/wiki/Linear_con ... _generator

usually that's also what a sane implementation of rand(0) does. when someone says using rand() is bad it's because there's no guarantee whatsoever.

tekelili
Posts: 1038
Joined: August 19th, 2009, 9:28 pm

### Re: Random or Pseudorandom?

In my experience for years among lot of games with randomess involved, I always found players that blamed their luck. I think our mind evolved to detect patterns, but our instinct works bad with "low chances".

here is an example I find often playing WC-MP Campaingn. An important unit with 70 def on forest die to a 4/4 attack hit. Chances this happens 0.81% so player say AI cheat. But what I really saw playing with that player several wc games, is that he risked important units on 70 def to 4/4 attacks about 5 times each map, what means he did 30 times in a campaing (wc has 6 maps), so he did it about 90 times in last 3 campaings (WC is hi replayable). When you do an action 90 times with 0.81% of succes, become sucesfull one time isnt so rare.

Other point of view is that player see like untochable his unit with 0.81% ctd, but he would never take a plain of a company whose flights crashes 0.81%, so here we can see human mind handle chances weighted by emotional factors.

Finally, my congrats to jb after lose an ulf in wc with 99.99% chance of sucess, he said: "meh, it could happen"

I doubt wesnoth rng works bad, a rng is a really easy thing to do well
Be aware English is not my first language and I could have explained bad myself using wrong or just invented words.
World Conquest II

Pentarctagon
Project Manager
Posts: 4435
Joined: March 22nd, 2009, 10:50 pm
Location: Earth (occasionally)

### Re: Random or Pseudorandom?

Before anyone posts here again, I would suggest re-reading Jetrel's post on the first page. This thread is not about what the player perceives as 'good luck' or 'bad luck' or if wesnoth's RNG should be changed to eliminate extreme swings in luck.
99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code

tekelili
Posts: 1038
Joined: August 19th, 2009, 9:28 pm

### Re: Random or Pseudorandom?

I thought first post exposed doubts about rng working well, and he gave "his perception" of rng behavior as only prove to those doubts. Sorry if I was wrong and my post wasnt related
Be aware English is not my first language and I could have explained bad myself using wrong or just invented words.
World Conquest II

Insinuator
Posts: 706
Joined: January 6th, 2004, 10:42 pm
Location: Portland, OR

### Re: Random or Pseudorandom?

Pentarctagon wrote:Before anyone posts here again, I would suggest re-reading Jetrel's post on the first page. This thread is not about what the player perceives as 'good luck' or 'bad luck' or if wesnoth's RNG should be changed to eliminate extreme swings in luck.
Then why don't you say what it is about. Because I see no replays, no facts, and no palpable evidence of RNG error.

What I do see is someone misquoting me twice and a moderator deleting my attempt to rectify.

I mean, if you don't believe me, believe Tryptic's own words:
tryptic wrote:Yeah, I understand there is a good chance that my brain is picking out patterns that SHOULD happen that often. I feel like I saw those situations more often than that (given that I only played 4-5 scenarios)
So, you're defending the opinion of someone who has only played 4-5 scenarios and now feels the need to lecture on how the RNG is flawed. Does nobody else see the silliness here?

Pentarctagon
Project Manager
Posts: 4435
Joined: March 22nd, 2009, 10:50 pm
Location: Earth (occasionally)

### Re: Random or Pseudorandom?

The thread is about the mathematical basis of wesnoth's RNG (as Jetrel stated), and we do not need to even begin a discussion regarding wesnoth and more deterministic RNG here.
99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code

Insinuator
Posts: 706
Joined: January 6th, 2004, 10:42 pm
Location: Portland, OR

### Re: Random or Pseudorandom?

The following comments are emotional reactions to atypical, but not impossible, situations that occur often enough in a scenario. Now, if emotional laments are what pass for "mathematical basis" on this forum, then excuse me.
Tryptic wrote:At first I told myself, "I won't load when things go bad" and stuck to it for several levels. I lost my first wraith...and my second, but eventually I managed to steamroll the orcs and come out with some living (sort of) rank-2 units. However every once in a while the game made me cringe. A battle where 2 units with 50% and 60% miss chance together launched 7 attacks and missed every one (chances of this happening = 0.32%) When I played Wesnoth before I hadn't taken a ProbStats class yet and didn't have the rock-solid understanding of probability I do now but things like that usually struck me as odd.

As the games wore on and my units became increasingly harder to replace, I found myself getting more and more upset. My Skeleton warrior died when the damage calculation said it was a 5% chance. But what surprised me was when I reloaded the game, tried again and it happened again. (chances of this happening = 0.25%)

Now, I understand that it's impossible to prove a random number generator bad simply because an unusual pattern has appeared, but this is not the first time this has happened! In this game events with less than a 5% probability seem to happen much more often than 5% of the time. I don't mean to whine (in fact if this project takes part in Google's Summer of Code program next year I will definitely apply) but I wonder if somebody could take a look at the random number generator, maybe run it through the DIEHARD test or something? I believe there's a good probability (no pun intended) that it isn't handling small probabilities correctly, or that it tends to not vary properly from one number to the next resulting in strings of similar results.

I know that random chance is a core part of Wesnoth, but at least the campaign part of it is built on ranking units up! In multiplayer it's fine, in campaigns it's heartbreaking to set up the best defensive line possible that will still advance to the objective fast enough, and have to do it a second time because the RNG sniped your best unit.

It sounds a bit odd to suggest that something so basic to the game has a flaw, but I can see how it could be missed. Some people whine because it's different from Fire Emblem without saying anything important. Anybody mature enough to be polite and work with the community to study the problem is also mature enough to think that they're only upset because they had to load, and decides to stay silent. If there WERE a problem with the RNG, no single player or developer would be able to tell. This is why I think there IS a problem and it hasn't been looked at yet.
I bear no ill will to Tryptic because I have felt similarly. But an eloquent argument does not translate to a substantial one. Dave and bjhartin already elaborated and addressed on the mathematics of the TWO examples Tryptic brought up. What further mathematical issues do you feel need to be addressed?

Sangel
Moderator Emeritus
Posts: 2232
Joined: March 26th, 2004, 10:58 pm
Location: New York, New York

### Re: Random or Pseudorandom?

Pentarctagon wrote:The thread is about the mathematical basis of wesnoth's RNG (as Jetrel stated), and we do not need to even begin a discussion regarding wesnoth and more deterministic RNG here.
I should note that for anyone who is interested in discussing a more deterministic RNG, this kind of discussion is welcome in the Experimental Corner. Indeed, it's one of the more popular topics of conversation there - see (1) (2) (3) (4) (5) - though please don't raise any-long-buried threads from the dead, or continue the conversation in this particular thread.
"Pure logic is the ruin of the spirit." - Antoine de Saint-Exupéry

Pentarctagon
Project Manager
Posts: 4435
Joined: March 22nd, 2009, 10:50 pm
Location: Earth (occasionally)

### Re: Random or Pseudorandom?

Insinuator wrote:I bear no ill will to Tryptic because I have felt similarly. But an eloquent argument does not translate to a substantial one. Dave and bjhartin already elaborated and addressed on the mathematics of the TWO examples Tryptic brought up. What further mathematical issues do you feel need to be addressed?
I believe you are misunderstanding me. I do not believe that there are further mathematical issues that need to be brought up or discussed (as you said, no proof for the OPs assertions has been provided). I was simply trying to keep the thread on topic.
99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code

Insinuator
Posts: 706
Joined: January 6th, 2004, 10:42 pm
Location: Portland, OR

### Re: Random or Pseudorandom?

Oh. Then I was misunderstanding you. I had no intention of derailing the topic. In fact, my main concern was the fact that someone misqouted me.

hiro hito
Posts: 201
Joined: November 23rd, 2006, 8:00 am

### Re: Random or Pseudorandom?

I think that the algorithm or the function(s) for the RNG implementation is good and works well. Recode it will be a non sense at this state of the game.

Just an observation from years over the game and this forum: the RNG is just not adapted for a strategic play style.
I mean not as strategic as most players want the game to be strategic.

The more you play the more you want to have more control on your strategy but you can't... RNG always decide who should win... All strategies depend of RNG mood: a random (and non human) fact. So in this case, even the best strategy has a flaw. But the flaw often comes with randomness peak... And you can't do anything except sigh... You can't even try to improve your strategy because randomness prevent it.

Here is the limit of the game... When you became to be an active player with best practice, in most real match up you always win/lose because of luck/unluck. It's a kind of bitter... It's a wanted option... Some find it good some other find it frustrating... And that's why developers don't assume the game to be competitive. It's just a matter of tast

It's a pity that all tast aren't represented, but I supposed it will be a lot of work... more than it's already be.
"Of course His Majesty is a pacifist. When I told him that to initiate war was a mistake, he agreed.Thus, gradually, he began to lead toward war."-Emperor ShÃ²wa (Enlightened Peace)'s chief cabinet secretary

Velensk
Multiplayer Contributor
Posts: 3991
Joined: January 24th, 2007, 12:56 am

### Re: Random or Pseudorandom?

I'll disagree with the above. In most real matches, a player will win or lose out of inability to stack the odds favorably enough in their favor. I cannot tell you how often I've seen good (or merely the better) player come into a fight with overwhelming odds of achieving advantages that will make their odds even more overwhelming and (surprise, surprise) coming out ahead. This happens far more often than them coming out behind. You can make your own odds, even against another good player.
"There are two kinds of old men in the world. The kind who didn't go to war and who say that they should have lived fast died young and left a handsome corpse and the old men who did go to war and who say that there is no such thing as a handsome corpse."

Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

### Re: Random or Pseudorandom?

If there are any technical questions remaining about the game's code for random number generation, please open a thread dealing only with that specific technical question (in the Coder's Corner not the User Forum please).

I think it is clear that this thread has served its purpose and the original question has been answered.
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."