randvalue Method

Joined
Oct 17, 2008
Messages
3
Reaction score
0
src\net\sf\odinms\scripting\npc Path

NPCConversationManager.java file input

Code:
public static int randomNumber(int min, int max) {
	return min + (int)(Math.random() * (max - min));
}

Usage

num = cm.randvalue(10 input = One of the numbers 1 to 10)
 
Last edited:
Code:
public static int randomNumber(int min, int max) {
	return min + (int)(Math.random() * (max - min));
}
Easier for generating numbers between an interval (e.g. random a pet ID from 50000000 and 50000040)

Not the real ID's btw =)


-Kerelmans
 
src\net\sf\odinms\scripting\npc Path

NPCConversationManager.java file input

Code:
 public void randvalue(int value) {
  return oRandom.nextInt(value);
 }

Usage

num = cm.randvalue(10 input = One of the numbers 1 to 10)
return new Random().nextInt(value);
People are going to get compiling errors if they haven't declared oRandom


Code:
public static int randomNumber(int min, int max) {
	return min + (int)(Math.random() * (max - min));
}
Easier for generating numbers between an interval (e.g. random a pet ID from 50000000 and 50000040)

Not the real ID's btw =)


-Kerelmans

Random.nextInt() is supposedly faster. Math.random() calls random.nextdouble() which calls random.next() twice, where as random.nextint() only calls .next() once on average.

Sorry if that was confusing but yeahs, since people are all fuss about performance then might aswell be judgmental on every thing.
 
return new Random().nextInt(value);
People are going to get compiling errors if they haven't declared oRandom




Random.nextInt() is supposedly faster. Math.random() calls random.nextdouble() which calls random.next() twice, where as random.nextint() only calls .next() once on average.

Sorry if that was confusing but yeahs, since people are all fuss about performance then might aswell be judgmental on every thing.

Very nice said, but we're talking about 0.1 ms or even less...
Here's some more info about random class if someone was interested:
 
Very nice said, but we're talking about 0.1 ms or even less...
Here's some more info about random class if someone was interested:

Probably quicker. Never knew you were good at java haha, long time no see
 
Funny how some method like this already was in my MapleCharacter.java

PHP:
    private static int rand(int lbound, int ubound) {
        return (int) ((Math.random() * (ubound - lbound + 1)) + lbound);
    }
 
Back