PKHeX.PKX.getRandomPID C# (CSharp) Method

getRandomPID() static private method

static private getRandomPID ( int species, int cg ) : uint
species int
cg int
return uint
        internal static uint getRandomPID(int species, int cg)
        {
            PersonalParser.Personal MonData = PersonalGetter.GetPersonal(species);
            int gt = MonData.GenderRatio;
            uint pid = Util.rnd32();
            if (gt == 255) //Genderless
                return pid;
            if (gt == 254) //Female Only
                gt++;
            while (true) // Loop until we find a suitable PID
            {
                uint gv = (pid & 0xFF);
                if (cg == 2) // Genderless
                    break;  // PID Passes
                if ((cg == 1) && (gv <= gt)) // Female
                    break;  // PID Passes
                if ((cg == 0) && (gv > gt))
                    break;  // PID Passes
                pid = Util.rnd32();
            }
            return pid;
        }