Sign in to follow this  
Sklo:D

[FIXED] Offspring name code bug

Recommended Posts

sigh.... Pls fix that.

 

com.wurmonline.server.creatures.Offspring

 

static String generateMaleName()

 

final int num = Server.rand.nextInt(100);
        if (num == 100) {
            return Offspring.MALE_NAMES[Server.rand.nextInt(Offspring.MALE_NAMES.length)];
        }

 

static String generateFemaleName() 

 

final int num = Server.rand.nextInt(100);
        if (num == 100) {
            return Offspring.FEMALE_NAMES[Server.rand.nextInt(Offspring.FEMALE_NAMES.length)];
        }

Share this post


Link to post
Share on other sites

For us dumb arses that dont code, what is wrong?

Edited by Pandalet
Spelling correction
  • Like 1

Share this post


Link to post
Share on other sites

 

Documentation:

The nextInt(int n) method is used to get a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence.

Note the Exclusive notation.

 

Reading:

final int num = Server.rand.nextInt(100);

Will pick a number from 0 to 99.

 

So its imposible that this ever be reached:

if (num == 100) {
            return Offspring.MALE_NAMES[Server.rand.nextInt(Offspring.MALE_NAMES.length)];
        } 

 

Edited by luvable
removed hidden post quoted
  • Like 1

Share this post


Link to post
Share on other sites

This is something I see a quite a bit. There's a lot of "bloat" code in the game right now.

                                int item = 795 + Server.rand.nextInt(16);
                                if (item == 1009) {
                                    item = 807;
                                } else if (item == 805) {
                                    item = 808;
                                }

 

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this