Is the API for `Random.ints(origin, bound)`, `.longs(origin, bound)`, etc., missing functionality?Awkward criteria when generating random sequenceWhy does Java switch on contiguous ints appear to run faster with added cases?Improving “randomness” when extending the range of rand()randomInt function that can uniformly handle the full range of MIN and MAX_SAFE_INTEGERJava Stream Api - is it possible to keep original map() input?Generating random integers uniformly in log spaceTurn random bytes to .NET decimal 0..1 fractional rangeUpdate Bounds of JButtons, JFrame, & etc?Algorithm to distribute a set of random integers from input file to N output (bucket) filesJava Stream API with non-pure functions chain
What is the word for reserving something for yourself before others do?
Why "Having chlorophyll without photosynthesis is actually very dangerous" and "like living with a bomb"?
Arthur Somervell: 1000 Exercises - Meaning of this notation
"to be prejudice towards/against someone" vs "to be prejudiced against/towards someone"
What would happen to a modern skyscraper if it rains micro blackholes?
Can I ask the recruiters in my resume to put the reason why I am rejected?
Why Is Death Allowed In the Matrix?
How do we improve the relationship with a client software team that performs poorly and is becoming less collaborative?
An academic/student plagiarism
How old can references or sources in a thesis be?
Why are electrically insulating heatsinks so rare? Is it just cost?
I’m planning on buying a laser printer but concerned about the life cycle of toner in the machine
Dragon forelimb placement
Has the BBC provided arguments for saying Brexit being cancelled is unlikely?
How to format long polynomial?
can i play a electric guitar through a bass amp?
Which models of the Boeing 737 are still in production?
Modeling an IPv4 Address
What does it mean to describe someone as a butt steak?
Is this a crack on the carbon frame?
Can I make popcorn with any corn?
If I cast Expeditious Retreat, can I Dash as a bonus action on the same turn?
Do I have a twin with permutated remainders?
Problem of parity - Can we draw a closed path made up of 20 line segments...
Is the API for `Random.ints(origin, bound)`, `.longs(origin, bound)`, etc., missing functionality?
Awkward criteria when generating random sequenceWhy does Java switch on contiguous ints appear to run faster with added cases?Improving “randomness” when extending the range of rand()randomInt function that can uniformly handle the full range of MIN and MAX_SAFE_INTEGERJava Stream Api - is it possible to keep original map() input?Generating random integers uniformly in log spaceTurn random bytes to .NET decimal 0..1 fractional rangeUpdate Bounds of JButtons, JFrame, & etc?Algorithm to distribute a set of random integers from input file to N output (bucket) filesJava Stream API with non-pure functions chain
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
It looks to me like it's impossible to include Integer.MAX_VALUE
and Long.MAX_VALUE
as possible random values when you create an IntStream
or LongStream
using bounds with the java.util.Random class.
This seems like a kind of annoying oversight. I can understand why they were trying to be consistent with the .doubles()
version, but it makes any attempt to get a stream of random int
s or long
s that could include the max value (but not the full range of values, obviously, since there are methods that do that) a lot more complicated than it needs to be.
Am I missing something or has this been discussed elsewhere?
java random java-stream
add a comment |
It looks to me like it's impossible to include Integer.MAX_VALUE
and Long.MAX_VALUE
as possible random values when you create an IntStream
or LongStream
using bounds with the java.util.Random class.
This seems like a kind of annoying oversight. I can understand why they were trying to be consistent with the .doubles()
version, but it makes any attempt to get a stream of random int
s or long
s that could include the max value (but not the full range of values, obviously, since there are methods that do that) a lot more complicated than it needs to be.
Am I missing something or has this been discussed elsewhere?
java random java-stream
Not really clear why do you believe that ... it's impossible to includeInteger.MAX_VALUE
? Or what do you mean by that, can you please add a block of code to clarify that.
– Naman
Mar 9 at 3:16
add a comment |
It looks to me like it's impossible to include Integer.MAX_VALUE
and Long.MAX_VALUE
as possible random values when you create an IntStream
or LongStream
using bounds with the java.util.Random class.
This seems like a kind of annoying oversight. I can understand why they were trying to be consistent with the .doubles()
version, but it makes any attempt to get a stream of random int
s or long
s that could include the max value (but not the full range of values, obviously, since there are methods that do that) a lot more complicated than it needs to be.
Am I missing something or has this been discussed elsewhere?
java random java-stream
It looks to me like it's impossible to include Integer.MAX_VALUE
and Long.MAX_VALUE
as possible random values when you create an IntStream
or LongStream
using bounds with the java.util.Random class.
This seems like a kind of annoying oversight. I can understand why they were trying to be consistent with the .doubles()
version, but it makes any attempt to get a stream of random int
s or long
s that could include the max value (but not the full range of values, obviously, since there are methods that do that) a lot more complicated than it needs to be.
Am I missing something or has this been discussed elsewhere?
java random java-stream
java random java-stream
asked Mar 9 at 2:43
TOBTOB
1,091923
1,091923
Not really clear why do you believe that ... it's impossible to includeInteger.MAX_VALUE
? Or what do you mean by that, can you please add a block of code to clarify that.
– Naman
Mar 9 at 3:16
add a comment |
Not really clear why do you believe that ... it's impossible to includeInteger.MAX_VALUE
? Or what do you mean by that, can you please add a block of code to clarify that.
– Naman
Mar 9 at 3:16
Not really clear why do you believe that ... it's impossible to include
Integer.MAX_VALUE
? Or what do you mean by that, can you please add a block of code to clarify that.– Naman
Mar 9 at 3:16
Not really clear why do you believe that ... it's impossible to include
Integer.MAX_VALUE
? Or what do you mean by that, can you please add a block of code to clarify that.– Naman
Mar 9 at 3:16
add a comment |
1 Answer
1
active
oldest
votes
You are correct. The javadoc states that the upper bound is exclusive. That means that you cannot use ints(lower, upper)
to get a stream that includes Integer.MAX_VALUE
.
Rationale?
This is possibly an edge-case that the designers didn't consider to start with1, or that they thought was not worth a "fix" that complicated the API.
Note that Random.nextInt(bound)
has this same problem, so this shortcoming in Random
has been present since Java 1.2. Therefore, another possibility is that the designers were aware of the shortcoming when they added the ints(...)
and longs(...)
methods, but decided not to address it because it would lead to an awkward inconsistency with the older methods.
1 - This is unlikely, IMO. The Java team were / are smart people. And it is clear from the source code that they are well aware of this now.
Anyway ... if you need streams of random numbers with a range that includes the MAX_VALUE
s, you can use the no-args overloads (ints()
and longs()
) and filter the streams. Alternatively, you could roll your own streams.
Thefilter
approach isn't too awful. Thanks!
– TOB
Mar 13 at 18:51
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55073514%2fis-the-api-for-random-intsorigin-bound-longsorigin-bound-etc-miss%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You are correct. The javadoc states that the upper bound is exclusive. That means that you cannot use ints(lower, upper)
to get a stream that includes Integer.MAX_VALUE
.
Rationale?
This is possibly an edge-case that the designers didn't consider to start with1, or that they thought was not worth a "fix" that complicated the API.
Note that Random.nextInt(bound)
has this same problem, so this shortcoming in Random
has been present since Java 1.2. Therefore, another possibility is that the designers were aware of the shortcoming when they added the ints(...)
and longs(...)
methods, but decided not to address it because it would lead to an awkward inconsistency with the older methods.
1 - This is unlikely, IMO. The Java team were / are smart people. And it is clear from the source code that they are well aware of this now.
Anyway ... if you need streams of random numbers with a range that includes the MAX_VALUE
s, you can use the no-args overloads (ints()
and longs()
) and filter the streams. Alternatively, you could roll your own streams.
Thefilter
approach isn't too awful. Thanks!
– TOB
Mar 13 at 18:51
add a comment |
You are correct. The javadoc states that the upper bound is exclusive. That means that you cannot use ints(lower, upper)
to get a stream that includes Integer.MAX_VALUE
.
Rationale?
This is possibly an edge-case that the designers didn't consider to start with1, or that they thought was not worth a "fix" that complicated the API.
Note that Random.nextInt(bound)
has this same problem, so this shortcoming in Random
has been present since Java 1.2. Therefore, another possibility is that the designers were aware of the shortcoming when they added the ints(...)
and longs(...)
methods, but decided not to address it because it would lead to an awkward inconsistency with the older methods.
1 - This is unlikely, IMO. The Java team were / are smart people. And it is clear from the source code that they are well aware of this now.
Anyway ... if you need streams of random numbers with a range that includes the MAX_VALUE
s, you can use the no-args overloads (ints()
and longs()
) and filter the streams. Alternatively, you could roll your own streams.
Thefilter
approach isn't too awful. Thanks!
– TOB
Mar 13 at 18:51
add a comment |
You are correct. The javadoc states that the upper bound is exclusive. That means that you cannot use ints(lower, upper)
to get a stream that includes Integer.MAX_VALUE
.
Rationale?
This is possibly an edge-case that the designers didn't consider to start with1, or that they thought was not worth a "fix" that complicated the API.
Note that Random.nextInt(bound)
has this same problem, so this shortcoming in Random
has been present since Java 1.2. Therefore, another possibility is that the designers were aware of the shortcoming when they added the ints(...)
and longs(...)
methods, but decided not to address it because it would lead to an awkward inconsistency with the older methods.
1 - This is unlikely, IMO. The Java team were / are smart people. And it is clear from the source code that they are well aware of this now.
Anyway ... if you need streams of random numbers with a range that includes the MAX_VALUE
s, you can use the no-args overloads (ints()
and longs()
) and filter the streams. Alternatively, you could roll your own streams.
You are correct. The javadoc states that the upper bound is exclusive. That means that you cannot use ints(lower, upper)
to get a stream that includes Integer.MAX_VALUE
.
Rationale?
This is possibly an edge-case that the designers didn't consider to start with1, or that they thought was not worth a "fix" that complicated the API.
Note that Random.nextInt(bound)
has this same problem, so this shortcoming in Random
has been present since Java 1.2. Therefore, another possibility is that the designers were aware of the shortcoming when they added the ints(...)
and longs(...)
methods, but decided not to address it because it would lead to an awkward inconsistency with the older methods.
1 - This is unlikely, IMO. The Java team were / are smart people. And it is clear from the source code that they are well aware of this now.
Anyway ... if you need streams of random numbers with a range that includes the MAX_VALUE
s, you can use the no-args overloads (ints()
and longs()
) and filter the streams. Alternatively, you could roll your own streams.
edited Mar 9 at 6:03
answered Mar 9 at 5:48
Stephen CStephen C
526k72586944
526k72586944
Thefilter
approach isn't too awful. Thanks!
– TOB
Mar 13 at 18:51
add a comment |
Thefilter
approach isn't too awful. Thanks!
– TOB
Mar 13 at 18:51
The
filter
approach isn't too awful. Thanks!– TOB
Mar 13 at 18:51
The
filter
approach isn't too awful. Thanks!– TOB
Mar 13 at 18:51
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55073514%2fis-the-api-for-random-intsorigin-bound-longsorigin-bound-etc-miss%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Not really clear why do you believe that ... it's impossible to include
Integer.MAX_VALUE
? Or what do you mean by that, can you please add a block of code to clarify that.– Naman
Mar 9 at 3:16