Jump to content

Simple "Random int between two numbers" method


Botre

Recommended Posts

	public static int rndmInt(boolean allowMinimum, int minimum, int maximum, boolean allowMaximum) {
		int min = minimum + (allowMinimum ? 0 : 1);
		int max = maximum  + (allowMaximum ? 1 : 0);
		return new Random().nextInt(max - min) + min;
	}

81104a7da9bf111c09aee6cfea1b34f4.png

^it's "exclusive" not "exlusive".

Edited by Botrepreneur
Link to comment
Share on other sites

Wouldn't MethodProvider.random(int,int) do the same. If you don't want to allow max or min, you reduce the interval?

 

Yep, this is to help people understand some of the mechanics behind such methods.

I prefer booleans to include / exclude limits, not the most type-friendly way to go, but improves the readability imo.

  • Like 1
Link to comment
Share on other sites

If you really want people to learn from this you probably should use the words exclusive and inclusive instead of allowed.

If you look at his comments, they say inclusive and exclusive. The way he did it is better than saying only inclusive and exclusive, because now people can look at his comments and make the connection to the method itsself. From that they can get that allow means inclusive and allow' would be non inclusive.

  • Like 1
Link to comment
Share on other sites

If you look at his comments, they say inclusive and exclusive. The way he did it is better than saying only inclusive and exclusive, because now people can look at his comments and make the connection to the method itsself. From that they can get that allow means inclusive and allow' would be non inclusive.

How are people supposed to learn if you have to dumb down simple vocab words?
Link to comment
Share on other sites

How are people supposed to learn if you have to dumb down simple vocab words?

By your logic we don't even need dictionaries. Why should we ever look at a dictionary? Why not just magically know every word ever naturally?

We need to learn somewhere, typically by making relations, which is exactly what he did.

Link to comment
Share on other sites

Questionable.

asexual gtfo

 

By your logic we don't even need dictionaries. Why should we ever look at a dictionary? Why not just magically know every word ever naturally?

We need to learn somewhere, typically by making relations, which is exactly what he did.

That is probably the worst comparison to this topic you could have ever came up with.

 

Jeez, all I do is make a logical suggestion and everyone goes ape shit.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...