Why does Random.nextInt() generating negative numbers?

As mentioned in the documentation, Random.nextInt() should return a pseudorandom, uniformly distributed int value between 0 (inclusive) and n (exclusive), and n must be positive. This means that we shouldn't expect any negative random number as an outcome. However, the fact is that when I was implementing this method to my program, negative numbers was generated. Why is it so? And how do I fix this problem if I need only positive random integers? Thanx!

As mentioned in the documentation, Random.nextInt() should return a pseudorandom, uniformly distributed int value
between 0 (inclusive) and n (exclusive), and n must be positive.You're confusing Random.nextInt() and Random.nextInt(int n).

Similar Messages

  • Can a sequence generate negative numbers?

    Hi
    Thank you for reading my post
    i think my sequence generate negative numbers , is it possible ?or somewhere in my application is incorrect ?
      CREATE SEQUENCE  "HR"."GLOB_SEQ"  MINVALUE 1 MAXVALUE 999999999999999999999999999 INCREMENT BY 1 START WITH 5 NOCACHE  ORDER  NOCYCLE ;is there anything that i made wrong which caused the negative numbers in my edit box ?
    type of my category_ID is number.
    Thanks

    Generally speaking yes you can generate negative numbers:
    SQL> create sequence seq1 increment by -1;
    Sequence created.
    SQL> select seq1.nextval from dual;
    NEXTVAL
    -1
    SQL> /
    NEXTVAL
    -2
    But if you have defined minvalue as 1 it is impossible because:
    SQL> create sequence seq1 increment by -1 minvalue 1 maxvalue 1000000 start with 1;
    Sequence created.
    SQL> select seq1.nextval from dual;
    NEXTVAL
    1
    SQL> /
    select seq1.nextval from dual
    ERROR at line 1:
    ORA-08004: sequence SEQ1.NEXTVAL goes below MINVALUE and cannot be instantiated
    SQL>
    So most probably someone simply inserted a row with negative values knowing that they'll never be in conflict with sequence generated values, or your code is buggy :)
    Generally for surrogate keys (assuming this is your case) you don't care what values they have.
    Gints Plivna
    http://www.gplivna.eu

  • Why does Illustrator change CMYK color numbers when set to preserve them?

    I'm using CS2 on Mac OSX 10.4. Recently I tried importing a Photoshop image into Illustrator and then matching a color in Illustrator to a color in the Photoshop document. But Illustrator changed the CMYK values of the color in the Photoshop document even though I have "Preserve CMYK colors" checked in the color setup window. Both applications and files are set to SWOP v2.
    I don't have the same problem when placing either Photoshop or Illustrator files into InDesign.
    I ended up recreating the project in InDesign to get consistent color, but I need to know how to make Illustrator preserve color numbers for the project that will come up for which I need Illustrator features.
    Thanks.

    So here we are at Illustrator CC and this very simple integration has not been fixed... because as far as I'm concerned... it is a BUG!
    Seriously, no offense to @Steve Fairburn... but that is just so archaic for a "suite" of programs that should work well together.
    There is absolutely NO need for CMYK colors to be valued beyond solid percentages in 1% increments in either Illustrator or InDesign!
    Here's a stupid workaround if you need to link images, and pull colors:
    Load the image as "linked" -> duplicate it and choose "embed" -> pull the colors and make swatches with the eyedropper tool... then throw it away. You could also just relink the file after an embed, making sure to check the Adanced Options checkbox.
    ADDITIONAL NOTES:
    1) why does InDesign give you the ability to "Reveal the Linked Image on the Desktop", whereas in Illy you can only reveal in Bridge?
    2) "placing" the same PSD/PDF image in InDesign and Illustrator: ID allows for correct eydropper color pulling, while IL does not until you embed it.

  • Why does content.setLayout()  generate runtime error?

    Hi all.
    Can some guru please explain to me why this code is generating following runtime error:
    java.lang.Error: Do not use SampleView.setLayout() use SampleView.getContentPane().setLayout() instead
         at javax.swing.JApplet.createRootPaneException(Unknown Source)
         at javax.swing.JApplet.setLayout(Unknown Source)
    This is the top level TopLevelMenu.java which calls SampleView.java
    public void init()
        // java code
        public void actionPerformed(ActionEvent aevt)
            SampleView sampleview = new SampleView();  // <-- OKAY so far
    }And here is the snippet for SampleView.java
    public class SampleView extends JApplet
        public SampleView()
          Container content = getContentPane();
          content.setLayout(newBorderLayout());  // <-- RUNTIME ERROR HERE
    }Instead of just correcting my code, could you please explain to me what is wrong with it?
    TIA :-)

    Thanks, but that was a typo, I'm still getting this runtime error!
    I tried several different ways e.g.
    public void init()
        Container content = getContentPane();
        JPanel headerPane = new JPanel(new BorderLayout());
        SampleView sampleview = new SampleView();
        headerPane.add(sampleview, BorderLayout.NORTH);
        content.add(headerPane);
    public SampleView()
      // etc
      return;
    }throws the same runtime error! Very puzzled!

  • Why does my itunes generated "purchased" playlist differ between different computers for the same library?

    One computer (my newer one with Lion) doesn't have any music before 7/2008 included as "purchased" but still has all the music in the general library that the other computer has listed in the "purchased" playlist (going all the way back to 2006) automatically generated by itunes. The other computer (the one with the correct purchased playlist) only has snow leopard but apparently can still work with the cloud as it has all the new downloads/purchases that have been completed on the other computer. Is this related to the Itunes plus thing - are all the songs before 7/2008 or whatever the date is not itunes plus and that's why they are not showing up as purchased in one computer? I think I can fix this by creating a special playlist of my own to sync between the two of them, but it would be nice to have both purchased lists be accurate for the synced library. Any thoughts or suggestions would be appreciated.

    You can transfer iTunes content from an iTunes library on a single computer only.
    Since these songs were purchased with the same iTunes account, you can download the song that is not in your iTunes library on the computer you will be syncing your iPhone with. Or you can download the song or songs direct on your iPhone.
    http://support.apple.com/kb/HT2519?viewlocale=en_US&locale=en_US

  • Why does Firefox remember Social Security numbers?

    I do not think this is normal operation, so I am unsure if this is Firefox's fault or the website's fault. I was just doing something on Paypal.com and when it came time to fill in my social security number, it had "suggestions" pop up under the fields with my SSN that it remembered before. Things like SS# and credit card numbers should not be remembered like this because it's a major security issue for if someone else uses my computer.
    I do not want to disable remembering fields entirely because that feature is useful to me. Names, addresses, phone numbers, emails, is all okay to be auto-filled in, but not something as extremely sensitive as SS#'s.
    Again, sorry if this is Paypal's fault. I will be contacting them instead if it is.
    Thank you for any information you can provide.

    SSN's might get stored as part of '''form history''' and not recognized as such, depending upon how the Field Name of the on-page form is labeled. Clear your '''Form and Search History''' or don't save that data to begin with.
    https://support.mozilla.org/en-US/kb/remove-recent-browsing-search-and-download-history
    Or get in the habit of opening a New Private Window when confronted with the need to insert SSN's which might get saved in Form History.

  • Why does the App Store say Numbers is installed when it isn't?

    Numbers crashed after the last update so I removed it from my Mac but now the App Store keeps saying it is still installed and won't let me re-download it. Any ideas? (I have restarted the computer)
    Thanks in advance...

    Hi Sparkoids,
    Perhaps you could try this. In Mac App Store, click on Account, then sign in, and "Reset all warnings for buying and download.' Then sign out and back in and try downloading again.
    (Also, make sure it's the Numbers in your Applications folder that you moved to the trash, not the Numbers that you may have in an iWork '09 subfolder within Applications. You'll probably want to keep the version that's in the subfolder because it's got features that the new Numbers does not have, at least not yet. The two versions for the most part coexist happily on the Mac.)
    SG

  • Why does the new update for Numbers app keep crashing when I try to edit old spreadsheet or build new one??

    hi there my numbers appp keeps crashing when i edit spreadsheets? I tried unistall and reinstall but this didnt fix it, i also signed into iclud and looked for blank spreadsheets as this was recommended on another site.

    hi there my numbers appp keeps crashing when i edit spreadsheets? I tried unistall and reinstall but this didnt fix it, i also signed into iclud and looked for blank spreadsheets as this was recommended on another site.

  • Why does the app vorlagen fuer numbers not work after ios7 update

    After ios7 update the app vorlagen fuer numbers won't open anymore, but vorlagen fuer numbers 2 works.

    I have been unable to find any app that works with Numbers on IOS7. I can still read them on IOS 6.1.3 with an iTouch.
    Numbers on IOS devices still works.

  • Why row_number() is not generating continuous numbers

    Hello Experts,
    I have :
    selectrow_number()over(partitionbycityorderbydate)rno,
    but I get the following:
    rno
    1
    4
    7
    10
    14
    18
    20
    25
    28
    31
    33
    36
    39
    42
    Please advise me.

    Hi Jingyang,
    Please ignore my post.
    Best Regards,
    Sqlquery9
    Hello,
    So, is the issue resolved? Row_Number() should return a sequential number of a row within a partition of a result set.
    Reference:ROW_NUMBER (Transact-SQL)
    Regards,
    Fanny Liu
    Fanny Liu
    TechNet Community Support

  • Random negative numbers

    A friend has asked me to implement a class that will produce random integers throughout the entire range of possible integer values. I know how to do this using Random() and generate "positive" numbers, but I can't figure out the algorithm(if there is one) to include the other 2 billion "negative" integer values.
    Ant help is greatly appreciated!

    But, you don't need a minus sign before it! nextInt() already returns a random integer through the entire range of positive and negative integers. It does exactly what you want!

  • Why does Contribute generate extraneous HTML code?

    Why does Contribute CS4 generate so much extraneous HTML code that is either redundant or conflicts with styles specified in our style sheet?  Below are examples of what we've encountered in the first two weeks of using the product.  It seems that, if we keep using Contribute, our website will soon be cluttered with junk code.  (Some of the special characters listed below and generated by Contribute do not display correctly in this forum.)
    1.       This simple Heading 1 tag: <h1>Heading 1</h1>
    gets replaced with this code:
    <p style="margin-top:0;"><span style="font-family:times new roman;font-size:16px;"><strong><span style="font-family:verdana; font-size:15px;">Heading 1 </span></strong></span></p>
    2.       This simple Heading 2 tag: <h2>Heading 2</h2>
    gets replaced with this code:
    <p><span style="font-family:times new roman;font-size:16px;"><strong><span style="font-family:verdana; font-size:13px;">Heading 2</span></strong></span></p>
    3.       This simple Paragraph tag: <p>Text</p>
    gets replaced with this code:
    <span style="font-family:verdana;"> </span><p style="margin-top:0;margin-bottom:0;"><span style="font-family:times new roman;font-size:16px;">Text<span style="font-family:verdana;font-size:13px;">Text</span></span></p>
    4.       The standard straight quote symbol (&quot;) gets replaced with left and right quotes (&ldquo;) (&rdquo;)
    5.       Apostrophe’s get replaced with “&rsquo;”.
    6.       Odd, non-visible (in some browsers) characters are inserted, like: “”.
    7.       Dashes get replaced with these special characters, which may not display in all browsers: “—”.
    8.       This non-standard style tag gets inserted at the top of some pages:
    <!--
    .style1 {font-size: 15px}
    -->
    </style>
    9.       Trademarks, which are reliably denoted with just ”&trade;”, get replaced with this code and these special characters, which may not display in all browsers: “<span style="font-size:12px;">â„¢</span>”.
    10.   The simple Heading 1 tag: : <h1>Heading 1</h1>
    gets overridden with this code:
    <h1><span style="font-family:times;font-size:16px;"><span style="font-family:arial;font-size:15px;color:black;">Heading 1</span></span></h1>
    11.   This simple Paragraph tag: <p>Text</p>
    has the inappropriate “ServNAV” navigation style applied to it:
    <p class=”ServNAV”>Text</p>
    12.   This simple Paragraph tag: <p>Text</p>
    gets replaced with this code:
    <p style="margin-top:0;"><span style="font-family:Times New Roman;font-size:15px;"><span style="font-family:verdana;font-size:12px;color:#333333;">Text</span></span></p>
    13.   Extra filler space gets inserted at the bottom of a page with this code:
    <p style="margin-bottom: 0;"> </p>
    14.   Internal links are created as absolute (<a href="http://www.company.com/subfolder/Client-One.html">) rather than relative links ()<a href="../subfolder/Client-One.html">.
    15.   Links to other sites are coded incorrectly,
    as in “<a href="www.company.com">www.company.com</a>”
    instead of: “<a href="http://www.company.com">www.company.com</a>”.
    16.   This simple bold Paragraph tag: <p><strong>About Company</strong></p>
    gets replaced with this
    <p style="margin-bottom: 0;"><strong>About Company</strong></p>
    17.   This simple Paragraph tag: <p>Text</p>
    gets replaced with this code:
    <p style="margin-top:0;"><span style="font-family:times new roman;font-size:16px;"><span style="font-family:verdana;font-size:13px;">Text</span></span></p>
    Message was edited by: JerryWeb

    I've just written a detailed list of editing tips for our internal use that, in addtion to using "Paste Text Only", describe how to avoid or re-key Microsoft Office curly quotes and apostrophes, use only Contribute's Insert | Special Characters, etc.
    In addition, I created a new role in which I made the following changes:
    Under Editing, under“General editing restrictions”, checked the “Prevent users from inserting images (except shared assets); under “Paragraph spacing, changed so “Enter key moves insertion point down:” “Two lines, as in web page editors (uses standard <p> tags”; under “Other editing options”, unchecked “Allow multiple consecutive spaces”
    Under Styles and Fonts, under “Styles and Fonts”, unchecked “Include CSS styles in the Style menu; unchecked “Allow users to apply fonts and sizes”; and unchecked “Allow users to apply font color and background color”.
    Under New Pages, unchecked “Create a blank page”
    Our initial experimentation indicates this eliminates most of the extraneous and junk HTML code that Contribute otherwise introduces. Time will tell. However, it requires contributors to be pretty rigorous.

  • Wi-Fi Connection Time Displays Negative Numbers

    Using an AEBS with the latest firmware 7.6.2 and OS X 10.7.2.  The Wi-Fi connection time appears to randomly start displaying negative numbers. It then counts down (up?) to zero and then displays positive numbers. Anyone else seen this?
    Regards.

    I have the same problem (Macbook 2008, 10.6.8 airport extreme 7.6). Has there been a fix? How do I report this bug, which seems to be affecting older machines as well? It's somewhat amusing, but is starting to become annoying.
    Melinda

  • Does Labview have a Random Number Generator for U16 with a periodicity greater than 64 Million instances of U16words and one with SEED as the connector?

    We are doing some testing that requires 64MegaWords be written to our DSP memory  with random values to do a validity check and without repeating sequences with using the previous value as the seed for the next and us passing it the initial seed.  The dice one doesn't meet that criteria, and I was not sure how the continuous random number generator parameters work and if any of them would meet this criteria. Anyone have any information that might help?
    Thanks,
    Sue

    Hi suem,
    There is no reason why you couldn't simply write a pseudo-random number generator by yourself. Simply select a random number algorithm you want to use and implement it in LabVIEW. You do not need to interface code written in another language in order to implement a pseudorandom number generator. If you have a DAQ card or something, you can also use inputr noise or some other hardware soruce to generate real random numbers. For that also LabVIEW is an excellent tool.
    Tomi
    Tomi Maila

  • Why does my iPad 2 type random letters?

    Why does my iPad 2 type random letters?

    It happens when I am trying to write emails, enter username or password info.  If a backspace to delete, often other numbers or letters appear.  In playing words with friends, the letters I am trying to place end up all over the board--do not go where I want them to.  My screens become "shakey" and if I shut down it usually corrects it--but not always.  The iPad 2 is less than a year old.  Might have to make an appt. at an Apple store unless you have another suggestion.  Thanks

Maybe you are looking for

  • Returning a FIOS TV Box

    I apologize if this is the wrong forum.  Would like to return 1 of my FIOS boxes.  I only use 2.  Will returning the unused box  lower my bill?  Thanks in advance for the assist. Solved! Go to Solution.

  • How do I create a Principal in Java

    How can I create a Principal in Java that can later be added to Websphere's Trust Map via a JAAS authentication module? Below code is not working as it throws the following exception: "Caused by: com.ibm.websphere.security.auth.WSLoginFailedException

  • TS1574 no sound on windows installed on my macbook pro

    Installed windows using boot camp on my macbook pro. now whenever I try to play a song, I see a red light from audio port & there is no sound. I can see this device in the list of playback devices. I tried updating the driver, but it says "windows ha

  • Canon MP620 simply wont go WiFi

    Hey I've been googling like a mad and reading through all MP620 topics in the Apple Discussions forum without any luck. I'm beginning to wonder if my Canon MP620 is defect. The printer works when plugged directly to my MacBook via USB. The printer do

  • Setting Up iPod sync options without having the iPod connected

    Is there any way to do this, to be able to set up what will sync with my iPod, what playlists to load for instance on my nano, or onto which nano, without having it connected? Thanks. All the best, Tom