RetroPie forum home
    • Recent
    • Tags
    • Popular
    • Home
    • Docs
    • Register
    • Login

    Random game it's not to much randomly :)

    Scheduled Pinned Locked Moved Ideas and Development
    random gamerandomemulationstatiogame selection
    24 Posts 5 Posters 2.0k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • DjDiabolikD
      DjDiabolik
      last edited by

      I try to explain better the situation:
      My setup it's a Pi4 whit latest and currently retropie (updated all about two weeks ago).

      I have a lot of system and i'm a big fan of the already built-in feature RANDOM SELECT :)

      Usually when i want to have some fun i turn on my Pi4 and i start to use the RANDOM feature to select a games from one of the systems I have available :)

      For made this example..... let's consider the NES collection :)
      The entire collection it's 3138 zip files :)

      I have divided all the titles into subfolders in a alphabetical orders... A..B...C..etc etc.
      When i use the RANDOM buttons apparently one games it's be selected whitout any problems. the problem is that this selection doesn't seem to be too causal.... infact every 2 or 3 consecutive presses of the random button i can see clearly ever the same games selected.
      IE for example I can see the same game selected only after two RANDOM pressed and on a collection of 3138 zip titles the choice should be more casual or somethings similar.

      I don't know if you get the idea..... how this RANDOM feature works ?
      can it be improved in some way to make it give more randomatic results?

      IanDaemonI 1 Reply Last reply Reply Quote 0
      • IanDaemonI
        IanDaemon @DjDiabolik
        last edited by

        Why did you separate your ROMs into subfolders?

        • 5 Favorite Arcade Games in MAME
        • Cocktail Cabinet Games
        • Check out the MAME RoW
        DjDiabolikD 1 Reply Last reply Reply Quote 0
        • DjDiabolikD
          DjDiabolik @IanDaemon
          last edited by DjDiabolik

          @iandaemon said in Random game it's not to much randomly :):

          Why did you separate your ROMs into subfolders?

          do you think this may be the problem?

          anyway simply to get a better order ....

          EDIT
          Anyhow i can also add this information.
          For mame2003plus I have not divided the roms into subfolders A..B..C..D etc etc. All zip files it's inside a single subfolders "mame2003-plus" on main "arcade" folder.
          and here too... i can also see the "random" current feature not too much randomly :)

          if it can help... and if i can made it... i can try to add a video example...

          IanDaemonI mituM 2 Replies Last reply Reply Quote 0
          • IanDaemonI
            IanDaemon @DjDiabolik
            last edited by

            @djdiabolik By the nature of choosing randomly you WILL get repeats close to one another. Do you want "random except recent selections"?

            I don't doubt that you're experiencing an issue, but splitting your ROM collection into subfolders seems unnecessary when you're using a GUI and not viewing the file structure directly. You could be creating issues like this (using features intended to work with another file structure).

            Does the random feature work when you have all of one system's ROMs in the same directory? The issue could be as simple as the Rand() function traversing subdirectories.

            • 5 Favorite Arcade Games in MAME
            • Cocktail Cabinet Games
            • Check out the MAME RoW
            1 Reply Last reply Reply Quote 0
            • mituM
              mitu Global Moderator @DjDiabolik
              last edited by mitu

              @djdiabolik said in Random game it's not to much randomly :):

              For mame2003plus I have not divided the roms into subfolders A..B..C..D etc etc. All zip files it's inside a single subfolders "mame2003-plus" on main "arcade" folder.
              and here too... i can also see the "random" current feature not too much randomly :)

              Are you using the 'random' help button in the mame2003-plus subfolder or from the arcade folder ? How many single games do you have in the arcade folder - directly there ?

              DjDiabolikD 1 Reply Last reply Reply Quote 0
              • DjDiabolikD
                DjDiabolik @mitu
                last edited by

                @IanDaemon
                apparently having separated the roms alphabetically in all subfolder called "A" "B" "C" it doesn't seem to cause any problems.
                Using the actual "Random" button I can see that the games are chosen from all the available folders...a title starting with the letter A can be chosen and, after another press of "Random" button a title whit letter C or P or any else.

                as already said the "problem" is that the same title reappears and is reselected usually after 2 or 3 consecutive pressed of "Random" button when absurdly with a choice of over 3000 titles there is a very wide choice and this should be less frequent.

                Try to understand me........ also whit my English knowledge it's not made me easy to explain what am I trying to say :)

                @mitu
                Apparently it's not important...... infact when i open the "Arcade" section and i press one time the "Random" button a games from "mame2003-plus" it's be selected.
                here too the same game is reselected very frequently..... usually after two or three consecutive press of "Random" button :)

                I am more and more convinced that with a video I would be able to make you realize what happens :)

                ...Really sorry for my bad english..

                mituM 1 Reply Last reply Reply Quote 0
                • mituM
                  mitu Global Moderator @DjDiabolik
                  last edited by

                  @djdiabolik said in Random game it's not to much randomly :):

                  I am more and more convinced that with a video I would be able to make you realize what happens :)

                  I realise what it happens, what's not clear to me is the full structure of the folder. Let's go again over the arcade folder:

                  • are you located directly in the arcade system where you press the Random game shortcut ?
                  • what folders do you have in the arcade system ?
                  • how many games do you have in the arcade folder (and not in sub-folders) ?
                  DjDiabolikD 1 Reply Last reply Reply Quote 0
                  • DjDiabolikD
                    DjDiabolik @mitu
                    last edited by

                    @mitu

                    1. Yes...
                    2. In arcade folder i have only one folder... "mame2003-plus" and "media" (contain the snapshot for gamelist.xml)
                    3. on mame2003-plus folder it's 2059 zip files.
                    IanDaemonI mituM 2 Replies Last reply Reply Quote 0
                    • IanDaemonI
                      IanDaemon @DjDiabolik
                      last edited by

                      @djdiabolik So...this? (ignore the file sizes)
                      d4de9b88-d2f0-4a5c-aab2-c81abbc5112c-image.png

                      • 5 Favorite Arcade Games in MAME
                      • Cocktail Cabinet Games
                      • Check out the MAME RoW
                      1 Reply Last reply Reply Quote 0
                      • mituM
                        mitu Global Moderator @DjDiabolik
                        last edited by

                        @djdiabolik I'll take a look.
                        I have a suspicion that 'random' counts only the games in the main folder (excluding the sub-folders) and that's why it's always picking the same number (or close to it, if you have few games in the main folder).
                        Could be related to the reports of users about screensaver not being 'random' enough - though it wasn't something I was able to reproduce.

                        DjDiabolikD 1 Reply Last reply Reply Quote 0
                        • DjDiabolikD
                          DjDiabolik @mitu
                          last edited by

                          @IanDaemon
                          Wait... i have the same folder structure also on a folder on windows (for made skraper of all roms).

                          db0e1fae-c9ee-4406-90b8-36e7e0288be4-immagine.png
                          This is the content of "/roms/arcade"

                          Inside mame2003-plus there are all roms zips

                          @mitu for curiosity... how is random choice made ?
                          each game has its own id and retropie chooses an id at random and selects it ?

                          Or simply retropie made a random step upward or downward respect the last game selected ?

                          mituM 1 Reply Last reply Reply Quote 0
                          • mituM
                            mitu Global Moderator @DjDiabolik
                            last edited by mitu

                            @mitu for curiosity... how is random choice made ?

                            • step 1 - count the games in the system.
                            • step 2 - pick a random number between 0 and N, where is N is the number of games
                            • step 3 - go to that game.
                            DjDiabolikD 1 Reply Last reply Reply Quote 1
                            • DjDiabolikD
                              DjDiabolik @mitu
                              last edited by

                              @mitu said in Random game it's not to much randomly :):

                              step 1 - count the games in the system.
                              step 2 - pick a random number between 0 and N, where is N is the number of games
                              step 3 - go to that game.

                              Oh ok..... therefore it may happen that the same game is reselected frequently if the variable N it is "generated not too randomly" :) ?
                              This reminds me of one thing... i have a good knowledge whit BASIC and AutoIT developing:
                              About 5 years ago I was writing a program where I needed to generate a randomatic variable.
                              If i remember correctly this variable need to obtain a value from 1 to 60....... I remember that this variable, after several tests, always seemed to obtain very similar values.

                              By way of workaround i "made/intent" a new routine of random choice.... i used a loop... an example:

                              1. RND(X) 1 to 10000 <- Temp variable
                              2. RND(N) 1 to 60 <- The variable i need
                              3. Made a complete loop whit variable X and regenerate variable N every time.

                              I don't know if I've made myself clear.... but thus the choice of the variable I needed immediately appeared more randomatic :)

                              IanDaemonI 1 Reply Last reply Reply Quote 0
                              • IanDaemonI
                                IanDaemon @DjDiabolik
                                last edited by IanDaemon

                                @djdiabolik I just tested the functionality and it appears to be working correctly on my end. Wouldn't your loop just complete the same "non-random selection" ten thousand times?

                                • 5 Favorite Arcade Games in MAME
                                • Cocktail Cabinet Games
                                • Check out the MAME RoW
                                DjDiabolikD 1 Reply Last reply Reply Quote 0
                                • DjDiabolikD
                                  DjDiabolik @IanDaemon
                                  last edited by

                                  @iandaemon mmmmmmmm....
                                  i don't have idea because it's happend on my pi4 setup :)

                                  I can say that if the same thing happened to me on a roulette wheel I could get rich :)

                                  Here it's very strange........ from a collection of about 2000 games if i press 15 times random button i can clearly see the same game selected from the 3 or 4 times.

                                  then we can say that it's just "randomness" :)

                                  IanDaemonI 1 Reply Last reply Reply Quote 0
                                  • IanDaemonI
                                    IanDaemon @DjDiabolik
                                    last edited by IanDaemon

                                    I believe that it's happening to you. I'm just trying to figure out the logic in my head. Selecting a random number from one to "N" should give you a random number within the constraints given. If the total number of games isn't "N" then where might "N" be coming from? Maybe there is some limit to the subfolders traversed and that is affecting "N"? I'm not sure, but this sounds like a mystery.

                                    • 5 Favorite Arcade Games in MAME
                                    • Cocktail Cabinet Games
                                    • Check out the MAME RoW
                                    DjDiabolikD 1 Reply Last reply Reply Quote 0
                                    • mituM
                                      mitu Global Moderator
                                      last edited by

                                      Can't reproduce this. I have a system with 1000+ games in a sub-folder, pressing X always gets me a random game. It doesn't matter whether there's a few games in the main folder or not.

                                      If you can zip your gamelist.xml and upload it somewhere I could try to reproduce it using it.

                                      1 Reply Last reply Reply Quote 0
                                      • LolonoisL
                                        Lolonois
                                        last edited by

                                        "Random Number Generation is too Important to be Left to Chance" -- Robert Coveyou

                                        Thanks to @DjDiabolik for bringing this up and sorry, the next sections will be technical. I can not judge what role your specific setup plays in the described effect, but I have evidence that some part is also caused by the current implementation. Maybe your described effect is a cumulation of both.

                                        I had a review of the codesegments in question, and the randomness is not really a unique randomness (if it would be a roulette it would be rigged). However, on my setup I have not noticed the same games selected/shown over short time / X presses, but some do show up more often in the slideshow than others and some have never been shown.

                                        Here is my analysis:

                                        1. Major flaw is the use of rand() in the code which does not spread evenly in RAND_MAX (=not uniform random as a ideal coin). Your effect @DjDiabolik may be caused by a non synchronized clock (which is likely as the Rpi has no real hardware clock as a PC and if the Rpi fake-hwclock is disabled or not updated on shutdown the Rpi time "stands still"). If system time is not updated and your system boots up with a tolerance of +/-0.5 sec you will most likely get the same random numbers from rand() as the random number generator gets initialized with the same time (which then defines the sequence of random numbers).

                                        2. It is very, very unlikely to get the screensaver image/video to show the last game in the overall gamelist list. If you maintain 3000 ROMs for example the likelyhood is not 1/3000 but 1/2147483647 (NB: 2147483647 = 2^31-1 which is RAND_MAX on Linux-Rpi). This subtle programmatically introduced non-uniforminess is something tried to be mitigated on the random game/random system selection but in a odd way.

                                        3. Whenever one uses custom images to display during the screensaver there is a modulo bias, so even if rand() would be uniform distributed random numbers, some custom images are shown more often than others.

                                        I lifted the code a while ago and I am happy to file a PR the next days: It utilizes a fast real uniform random number generator (not depending on time as sole source of entropy/initialization), uses the benefits of C++11 and has less code to accomplish the same.

                                        dankcushionsD 1 Reply Last reply Reply Quote 1
                                        • DjDiabolikD
                                          DjDiabolik @IanDaemon
                                          last edited by

                                          @iandaemon said in Random game it's not to much randomly :):

                                          I believe that it's happening to you. I'm just trying to figure out the logic in my head. Selecting a random number from one to "N" should give you a random number within the constraints given. If the total number of games isn't "N" then where might "N" be coming from? Maybe there is some limit to the subfolders traversed and that is affecting "N"? I'm not sure, but this sounds like a mystery.

                                          lol...i don't have idea. I'm probably the one who's noticing it too much :)

                                          @mitu said in Random game it's not to much randomly :):

                                          Can't reproduce this. I have a system with 1000+ games in a sub-folder, pressing X always gets me a random game. It doesn't matter whether there's a few games in the main folder or not.

                                          If you can zip your gamelist.xml and upload it somewhere I could try to reproduce it using it.

                                          it's not a problems.... tomorrow or next time i turn on my Pi4 i get for you the gamelist.xml of my NES system. It's about 3000 roms divided alphabetically by subfolder and try to upload on zippyshare or somethigs similar (suggest if you have a preferred host site).
                                          i can also provide the gamelist.xml of my arcade system whit only mame2003-plus collection. here all roms it's inside a single subfolders and also here I can notice this strange randomness :)

                                          Guys... what seems strange to me it's this. with a smaller collection of roms obviously the chances that the same game will be selected randomly more times is higher:
                                          For example.. Atari Linx entire collection it's only 95 titles. But with a larger collection, in theory, it should be the exact opposite :)

                                          @Lolonois i have read carefully your explanation...... but it's too much techicals for my knowledge here :)

                                          mituM 1 Reply Last reply Reply Quote 0
                                          • mituM
                                            mitu Global Moderator @DjDiabolik
                                            last edited by

                                            @djdiabolik said in Random game it's not to much randomly :):

                                            i can also provide the gamelist.xml of my arcade system whit only mame2003-plus collection. here all roms it's inside a single subfolders and also here I can notice this strange randomness :)

                                            It doesn't matter how many games are, as long as the issue occurs with that system.

                                            1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post

                                            Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.

                                            Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.