How random is random?

For test results, bug reports, announcements of new builds etc.

Moderators: another_commander, winston, Getafix

Post Reply
User avatar
spara
---- E L I T E ----
---- E L I T E ----
Posts: 2676
Joined: Wed Aug 15, 2012 4:19 am
Location: Finland

How random is random?

Post by spara »

I've been testing my RH shipset oxp and been printing into the log the names of the ships that get spawned. And for some reason there is one name that keeps on popping: "Grandmaster Nemoricus". RandomHits name is created by selecting first name and second name from arrays in descriptions.plist.

To my calculations the probabilities should be as follows:

Probability for Grandmaster is 1/3 * 2/5 * 1/47 that approximates to 0.0028
Probability for Nemoricus is 1/3 * 1/4 * 1/55 that approximates to 0.0015

Oolite is 1.77.1. Any idea?
User avatar
Commander McLane
---- E L I T E ----
---- E L I T E ----
Posts: 9520
Joined: Thu Dec 14, 2006 9:08 am
Location: a Hacker Outpost in a moderately remote area
Contact:

Re: How random is random?

Post by Commander McLane »

How random is random?
The answer is: not very. The mechanism that selects entries from descriptions.plist is based on a sequence created from the seed. This means that at every game start the same sequence is generated and used, thus you always get the same names. Certain events reset the sequence, starting from its first value again, which is why you see a certain variance as time passes, because when one of those events occurs is not predictable.

In addition to that, the sequence only consists of two-digit numbers (I believe). Thus any key in descriptions.plist that contains more than 100 entries is wasted. No more than 100 of its entries can ever be randomly selected.

These are natural limitations of using descriptions.plist and extracting values from it by the bracket method. The only real way to overcome them and solve the problem of repeating random numbers is to convert descriptions.plist to an JS-array and extract the entries via Math.random() in JS.
User avatar
spara
---- E L I T E ----
---- E L I T E ----
Posts: 2676
Joined: Wed Aug 15, 2012 4:19 am
Location: Finland

Re: How random is random?

Post by spara »

Ok, that explains a lot. Thanks for the explanation. Any idea if this will change in the future? I'm pondering about the conversion job and if it's worth the trouble. With RandomHits the conversion to js is not going to be very straightforward as descriptions include bracketed references which again include bracketed references... and so on.
User avatar
Commander McLane
---- E L I T E ----
---- E L I T E ----
Posts: 9520
Joined: Thu Dec 14, 2006 9:08 am
Location: a Hacker Outpost in a moderately remote area
Contact:

Re: How random is random?

Post by Commander McLane »

spara wrote:
Ok, that explains a lot. Thanks for the explanation. Any idea if this will change in the future?
I think not. It's part of the legacy scripting engine, and thus it's sort of obsolete anyway. Changing it would also break compatibility with 1.65, and therefore stability.

Converting the descriptions.plist to JS arrays is a tedious job, indeed. I'm currently in the process of doing it for the comms messages of [EliteWiki] personalities, and I can only do so much copying and pasting each session before my brain melts. And it's going to be much worse for RH, because of the sheer size of it. But it'll definitely be worthwhile. Apart from getting rid of the random generator limitations, I believe that decriptions.plist is also a rather time consuming way of extracting random strings.
spara wrote:
With RandomHits the conversion to js is not going to be very straightforward as descriptions include bracketed references which again include bracketed references... and so on.
In randomshipnames I'm using independent functions for each level of recursion. Each function can (randomly) either insert a random string or call another function that will in turn either insert a random string or call another function, etc. That's how I would design it for RH as well.
User avatar
Svengali
Commander
Commander
Posts: 2370
Joined: Sat Oct 20, 2007 2:52 pm

Re: How random is random?

Post by Svengali »

I haven't checked what RH needs, but maybe CCL_PhraseGen can help -> https://app.box.com/s/m7zgdpe7tg0492w9ikxi

Edit: After taking a look at RH I can only say - keep the plists.
User avatar
spara
---- E L I T E ----
---- E L I T E ----
Posts: 2676
Joined: Wed Aug 15, 2012 4:19 am
Location: Finland

Re: How random is random?

Post by spara »

Svengali wrote:
After taking a look at RH I can only say - keep the plists.
:lol:

Quite a lot of work there alright. If I ever touch it, I'll be doing more than just converting it. I would very much like to change the naming of ships to RandomShipNames engine so that RandomHits better integrates to the game. Currently used pilot names would only appear in contract offerings. We'll see. If I'm bored at some point, I might take a longer look at it.
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Re: How random is random?

Post by Eric Walch »

With Oolite 1.75 and older, it was even worse. Some events did reset the random seed, resulting in (almost) always getting the same results. In Random Hits main script, you therefor find the lines:

Code: Select all

            if (0 < oolite.compareVersion("1.76")) // bad randomness is not fixed in 1.75 so we still need the next two lines.
            {
                count = Math.round(Math.random()*10);
                for (var k=0; k<count; k++) name = expandDescription("[nom2]"); // mix up the random generator
            }
I used that in the part that created the hit-pages. I think it was touching the systemname, did reset the seed.

And the fact that expanding from the plist is biassed towards certain results, is also the reason I used the Js Math.random() function to select the ship for the mark. That one I wanted really random.
User avatar
spara
---- E L I T E ----
---- E L I T E ----
Posts: 2676
Joined: Wed Aug 15, 2012 4:19 am
Location: Finland

Re: How random is random?

Post by spara »

Thanks Eric. I had noticed those lines earlier, but they did not make sense then. Now I see the meaning of those.

One more question. Is Oolite's own randomName function random enough to be used to replace the name lists used in RandomHits?
User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4072
Joined: Fri Nov 11, 2011 6:19 pm

Re: How random is random?

Post by cim »

So ... okay:
1) descriptions.plist is not itself obsolete or part of legacy scripting. It's by far the easiest way for us to include translatable strings in the core game. Randomisation using it is also not obsolete - it just needs improvement.
2) Without testing I would guess that descriptions.plist was at worst no slower than using JS arrays, just because JS is an intrinsically slower language than the Objective-C parser for descriptions. In terms of memory usage descriptions.plist is considerably better than a JS array since the memory usage is in the general pool rather than in the much smaller JS pool.
3) There are two separate random number generators used in Oolite. The descriptions.plist one is Elite-compatible to ensure that planet descriptions stay as in previous versions. It is limited to two digits - hex digits, not decimal, so 256 is the absolute limit, and anything above about 16 entries will have seriously skewed probabilities - but importantly it also has serious correlation problems between successive values, so while any individual number has an even probability, once you know the first number the following numbers are much more constrained.

Seed resets are no longer a problem, however - seed values can be saved and loaded: if a particular seeded sequence is needed, the old state of the generator is saved, the seeded sequence is generated, and the old state is restored so the main chain of random numbers remains sensible.

There is a second random number generator in Oolite - the Ranrot algorithm - which is extremely high quality (certainly better than the random number generator used by the JS Math.random() function). It would probably make sense to use this instead of the Elite-compatible one except in contexts where Elite-compatible behaviour (basically only planetary info) was required. I'll add that to 1.79
spara wrote:
Is Oolite's own randomName function random enough to be used to replace the name lists used in RandomHits?
It basically just expands %N, which is not great. I'd stick with the name lists you already have, though sometimes taking a name from the existing list and sometimes expanding "%N [nom]" would give you more variety.
Post Reply