jeudi 16 novembre 2023

Random number generation is giving a number in a smaller range [duplicate]

I have a console program for a gacha system, which is responsible for randomly generating "skins" between 5 "qualities" with their own rarity, among one of these is the common quality which has 3 items, I programmed it to randomly generate numbers again but instead of using 0 to 101, I used 0 to 4, because there are only 3 items, when I finished the program and checked that everything was fine, I realized that the times it came out common, only the first of the 3 was shown articles, when testing with debugging, I realized that the variable in charge of indicating which option of the 3 would be shown, always had a value of 0

This is a part of my code, specifically the one that is failing, even i tried by raising the values in the Random().Next(0,4) to Random().Next(0,34) and the values were the same but instead, the values were only between 0 and 11:

int commonSkinIndex = new Random().Next(0, 34);
if (commonSkinIndex <= 11)
{
    Console.Write(" Value: " + commonSkinIndex + " Skin: 8-Bit\n");
} 
else if (commonSkinIndex > 11 && commonSkinIndex < 22)
{
    Console.Write(" Value: " + commonSkinIndex + " Skin: Gothic\n");
}
else 
{
    Console.Write(" Value: " + commonSkinIndex + " Skin: Holy\n");
}

Even I was trying changing thecommonSkinIndex <= 11 to commonSkinIndex < 11 and for the else if (commonSkinIndex >= 11 && commonSkinIndex < 22) the difference between the previus line was that random could now include the number 11, also, I don't believe that this may change the results, but above all that part, there's this:

else if (output / 100 <= commonChance && output / 100 > uncommonChance)
{
(...)
}

Also, I made sure each loop is random, so this repeats every 500ms (this loops 10 times)




Aucun commentaire:

Enregistrer un commentaire