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;








0















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 ints or longs 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?










share|improve this question






















  • 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


















0















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 ints or longs 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?










share|improve this question






















  • 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














0












0








0








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 ints or longs 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?










share|improve this question














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 ints or longs 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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 9 at 2:43









TOBTOB

1,091923




1,091923












  • 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

















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













1 Answer
1






active

oldest

votes


















0














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_VALUEs, you can use the no-args overloads (ints() and longs()) and filter the streams. Alternatively, you could roll your own streams.






share|improve this answer

























  • The filter approach isn't too awful. Thanks!

    – TOB
    Mar 13 at 18:51











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
);



);













draft saved

draft discarded


















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









0














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_VALUEs, you can use the no-args overloads (ints() and longs()) and filter the streams. Alternatively, you could roll your own streams.






share|improve this answer

























  • The filter approach isn't too awful. Thanks!

    – TOB
    Mar 13 at 18:51















0














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_VALUEs, you can use the no-args overloads (ints() and longs()) and filter the streams. Alternatively, you could roll your own streams.






share|improve this answer

























  • The filter approach isn't too awful. Thanks!

    – TOB
    Mar 13 at 18:51













0












0








0







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_VALUEs, you can use the no-args overloads (ints() and longs()) and filter the streams. Alternatively, you could roll your own streams.






share|improve this answer















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_VALUEs, you can use the no-args overloads (ints() and longs()) and filter the streams. Alternatively, you could roll your own streams.







share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 9 at 6:03

























answered Mar 9 at 5:48









Stephen CStephen C

526k72586944




526k72586944












  • 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
















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



















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived

Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme