Generate a random number

How do you generate a random number?

You can also check out Math.random() which returns a
double value between [0..1)You could, depending on your needs, but if you do want ints then you're better off using nextInt from java.util.Random, as outlined by the author here:
http://java.sun.com/docs/books/effective/excursion-random.html
(and what was wrong with 125?! I thought that was a perfectly fine random number...)

Similar Messages

  • How can you generate a random number?

    Say I have a timer, and I need it to choose a random number between 100 and 1000. How would I do that?
         timer.delay(***RANDOM***);Thanks!

    I have this, and it's working for me:
    int j = rand.nextInt(500);
    But I actually want it to generate a random number between 100 and 500, not 0 and 500. How could I do this?
    ~Dac

  • Generate a random number and make it STAY after "save"

    I searched around this forum and found that I can use this code to generate a random number:
    //this.rawValue = Math.round(Math.random() * 1000000);
    Works great. only problem is, once I practice on the "real" form and save, close, and reopen - it changes the random number every time. I need to figure out a way to make it save the 1st number it generates when someone opens the form and types info in it....then they save and close, etc.
    Can anyone help me? Thanks!!

    Example steps:
    1. Add a hidden field to the same subform with name 'hiddenField'.
    2. First time you open 'hiddenField' rawValue will be null.
    3. where ever you run the code to generate random number use scenario like this.
    if (hiddenField.isNull) {
    this.rawValue = Math.round(Math.random() * 1000000);
    }else {
    this.rawValue = hiddenField.rawValue;
    Hope this thelps.
    SekharN

  • How generate a random number that is between 0 and 15! (0-15)

    how generate a random number that is between 0 and 15 ??? (0-15)
    pls tell me, thx!!!!!!!!!!!!!!!!!

    import java.util.Random;
    Random r = new Random();
    int mynumber = r.nextInt()%16;
    For (2^1)-1 number use:
    -> int mynumber = r.nextInt()&15; // speedup

  • How to generate a random number with at least 6 digits?

    Hi all,
    All is in the question. :-)
    I would like to generate a random number but the function "random
    number" in Labview isn't accurate enough.
    Do you know an algorithm to generate a random number of 6 or more
    digit?
    Thanks,
    PF

    Hi PF,
    It's simple. Use 2 random number functions in the same process. Now you
    should have 2 distinct random numbers that have the same accuracy. Let's say
    LV gives accuracy up to the thousandth (0.XXX), now if you divide one number
    by 1000 and then add to the other number you should then have something like
    0.XXXXXX. Actually, LV random number function can give up to about 17 digits
    (decimal). If you are looking for more digits (>17 digits), the idea above
    may not work, then the last thing you may want try is to generate two or
    three random numbers then convert all these decimal numbers to fractional
    strings chop off the 0 and dot then concatinate them together. After all
    it's still a random number. How many digits do you want to get? Make sure
    the indicators acce
    pt that many digits?
    Good luck
    Louis.
    P-F wrote in message
    news:[email protected]..
    > Hi all,
    >
    > All is in the question. :-)
    >
    > I would like to generate a random number but the function "random
    > number" in Labview isn't accurate enough.
    >
    > Do you know an algorithm to generate a random number of 6 or more
    > digit?
    >
    > Thanks,
    >
    > PF

  • How to Build a VI that generates a random number between 1 and 80 ....Help!!!!

    Build a VI that generates a random number between 1 and 80 
    Divides the random number by a number specified in the front panel.
    If the inputted number is zero, the VI program should turn on a LED in the front-panel to indicate a divide by zero error.
    Solved!
    Go to Solution.

    One quick question Edward, was the answer just in time for your monday morning class.
    Ton
    Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
    Nederlandse LabVIEW user groep www.lvug.nl
    My LabVIEW Ideas
    LabVIEW, programming like it should be!

  • How to generate a random number within a specified tolerance and control that tolerance.

    I am trying to simulate data without using a DAQ device by using a random number generator and I want to be able to control the "range" of the random number generated though.  On the front pannel, the user would be able to input a nominal number, and the random number generator would generate numbers within plus or minus .003 of that nominal number.  The data would then be plotted on a graph.  Anyone know how to do this?  Or if it's even possible?
    Just for information sake, the random number is supposed to look like thickness measurements, that's why I want to simulate plus and minus .003 because the data could be thinner or thicker than the nominal.  
    Thanks in advance!!
    Solved!
    Go to Solution.

    You can create a random number with a gaussian probability profile using two equal distributed (0...1) random numbers and applying the Box Muller transform.
    I wrote one many years ago, her it is. (LabVIEW 8.0). 
    Message Edited by altenbach on 04-12-2010 09:13 PM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    BoxMuller.vi ‏10 KB

  • Re: Generating a random number between 1-10;

    How do I generate a number between 1-20? I saw how to on this forum once, but I can't find it, and I don't have much time to look. Sorry for any inconvinience. What I want to do is assign to the variable x the random number.
    Thanks.
    Virum

    Random rnd = new Random();
    int x = rnd.nextInt(20)+1;

  • _dynSessConf - How to tweak logic to generate the random number.

    Hi,
    Can someone please let me know how we can tweak the logic when the random session confirmation number is generated and added as _dynSessConf.
    We have a requirement where this random number needs to be a bit longer than the currently generated default value.
    Regards,
    Saurav

    The session confirmation number used for _dynSessConf is already a randomly generated cryptographic number of long type which is hard to guess. Anyways, if you want to further modify it here is one of the approach that I can suggest.
    You can probably start with the component /atg/dynamo/servlet/sessiontracking/SessionIdGenerator in the component browser. In its details you will find it has a uniqueIdGenerator property which points to /atg/dynamo/servlet/sessiontracking/UniqueIdGenerator. Following on further it would eventually lead you to the components /atg/dynamo/service/random/SecureRandom and /atg/dynamo/service/random/SecureRandomConfiguration. Look at the service configurations of these components and see if you can get something which you can change or customize to meet your requirements.

  • Any function generating a random number ?

    Is there any function which yields a random number every time from a given list of numbers ?
    e.g.
    Consider table t as :
    invoice_no
    123
    456
    789
    654
    321
    987
    I want a function executed manually yielding a random invoice no.
    How can i achieve ?
    Regards
    Capri !!!

    Cannot reproduce. There must be some misunderstanding.
    The selected invoices are just numbered and the required number of random positions is extracted.
    Don't know how a valid position can contain a nonexisting invoice number as (valid I presume) invoice numbers were selected before being numbered.
    I think the first version was a little unfair: The last invoice couldn't be extracted as dbms_random.value(low,high) can return low but cannot return high.
    select invoice_no
      from (select invoice_no,row_number() over (order by null) the_row
              from invoices
             where <your criteria here>
    where the_row in (select trunc(dbms_random.value(1,(select count(*) + 1 from invoices)),0)
                         from dual
                        connect by level <= :how_many_to_draw
                      )Regards
    Etbin
    In my solution I overlooked the possibility that the same invoice could be extracted more than once. So better to follow Dave's suggestion and choose MichaelS's solution
    with
    invoices as
    (select trunc(dbms_random.value(:lower_limit,:upper_limit),0) invoice_no
       from dual
      connect by level <= :number_of_rows
    select invoice_no
      from (select invoice_no
              from invoices
    --          where <your criteria here>
             order by dbms_random.value
    where rownum <= :how_manyMessage was edited by:
    Etbin

  • Is there any way to generate random number in CPO

    Requirement : -
    > I want  to generate a random number from set of 1-9 numbers .is there any way in cpo ?
    Thanks
    Siva

    I created a process that uses 3 steps, all of which happen inside the engine rather than having to span out to a script, so it runs a lot faster.
    Technically, it's pseudo-random...
    Predefine Output Variable "Random Number" as type "Numeric"
    Step 1:  Format Date
      Format string: fffffff 
        (that's seven lower-case letters "f")
      Original date: [Process.Start Time]
    Step 2: Format Date
      Format string: ff\0\0\0\0\0
      Original date: [Process Start Time]
    Step 3: Set Variable
      Variable to update: [Process.Variables.Output.Random Number]
      New value: ([Workflow.Format Date.Formatted Date]-[Workflow.Format Date (2).Formatted Date])/100000
    This returns a basically random number between 0 and 1 (so you can mulitply it by your maximum value) based on the numeric fraction of a second of the start time of the process.

  • Need help with a JavaScript to generate random number

    Hi
    First things first. I don't know the J of JavaScript.
    When I was thinking of some readymade solution to generate a random number in Captivate, I found this on a LinkedIn forum.
    1) Add a user variable to your project called "randomNumber". It's value can be zero.
    2) Add a Text Caption with "$$randomNumber$$" in it, to check whether your script is working.
    3) Add a button to the slide. Give it an On Success Action of Execute JavaScript. Turn off it's "Continue Playing the Project" checkbox.
    4) Add the following text in the button's Script_Window:
    var objCP = document.Captivate;
    var rand = 1 + Math.floor(Math.random() * 10);
    function onButtonClick(){
    objCP.cpEISetValue('randomNumber', rand);
    onButtonClick();
    However, this is (as the poster in the forum warned) not working for Captivate 7. Can somebody please help?
    I am open for any other methods of getting the same result.
    Thanks in advance,
    Sreekanth

    Hi Sreekanth,
    When testing, make sure you are testing from a web server where the web address begins with http or https.  When setting the captivate variable "randomNumber" try this instead:
    objCP.cpEISetValue('m_VarHandle.randomNumber', rand);
    That will only work for SWF output.  If you want it to work for both HTML5 and SWF output, try this code:
    window.onButtonClick = function(){
              var rand = generateRandomNumber(1, 10);
              setCpVariable('randomNumber', rand);
    window.generateRandomNumber = function(min, max){
              var randomNum = 0;
              if(!isNaN(parseFloat(min)) && !isNaN(parseFloat(max))){
                        min = Number(min);
                        max = Number(max);
                  randomNum = Math.floor(Math.random() * (max - min + 1)) + min;
              return randomNum;
    window.setCpVariable = function (cpUserVariableName, variableValue) {
              /* Check for HTML5 vs. SWF output */
              if (typeof window.cp === 'undefined') {
                        /* We have SWF output, so Get the Captivate Object */
                        var objCp = document.getElementById('Captivate');
                        if (objCp && objCp.cpEISetValue) {
                                  /* Set the Captivate User variable with the JavaScript variable, variableValue */
                                  objCp.cpEISetValue('m_VarHandle.' + cpUserVariableName, variableValue);
              } else {
                        /* We have HTML5 output */
                        /*If variable does not exist off of the window object, then use the variables manager*/
                        if (typeof window[cpUserVariableName] === 'undefined') {
                                  if (cp.vm && cp.vm.setVariableValue) {
                                            cp.vm.setVariableValue(cpUserVariableName, variableValue);
                        } else {
                                  window[cpUserVariableName] = variableValue;
    window.onButtonClick();
    Be sure to test this from a web server or else local security will prevent the javascript from executing.
    Best,
    Jim Leichliter

  • Updating a field that generates random number when form is reset..

    I have a field that will generate a random number when the form is initially opened. THis fiekd runs an initialization script of : var randomnumber=Math.floor(math.random()*99999) and then a calculation script of randomnumber.
    The field value is set as Calculated - Read Only.
    When I hit the Reset button and it clears all the input fields for the form i would like to have it re calculate a new random number. I am not knowledgable in any scripting language and what I have so far I found by searching the forums.
    Any help would be appreciated.
    Thanks

    I don't know if it should matter, but the field to update is on a page other than the one with the reset button. And, the above is not working.
    I tried it as you stated above fieldname.rawvalue=randomnumber and I tried pagename.fieldname.rawvalue=randomnumber

  • Random Number Generator with Page Jump

    Hi,
    I was wondering if it is possible to write a script with Javascript that will:
    - generate a random number
    - when a specific random number is generated, a certain page in the document is loaded.
    For example, when 4 is generated, out of 1 to 6, you would jump to page 10, when 5 is generated, you
    would jump to page 20, etc.
    The idea is that when you press the button to which this javascript is linked, you will automatically
    jump to a random page.
    Would this be possible at all?
    Thanks!
    Regards,
    Fabian

    That is a good idea. Thanks.
    I know I should be able to do this myself, but I am really not very good when it comes to programming. Could you perhaps show me an example of the schripting lines I should use?
    I am learning about programming, but I am still not very good.
    Thanks!
    Regards,
    Fabian

  • Help: JSP Random Number Generator

    hello every one,
    Im trying to generate a random number using currentTimeMillis(), in Jsp, can you help me out and advice me how can this be done please.

    First you say you want a random number, then you say you want a unique one. Which is it?
    Random numbers do not normally guaruntee uniqueness.
    is there away i could use the currentTimeMillis(), What would you use it for? System.currentTimeMillis() is commonly used as a seed for a random number generator. The java.util.Random class uses it like that - take a look at that API link.
    Or if its a homework question state the exact requirement - I'm guessing here.

Maybe you are looking for

  • Report on PO No. and PO Creater

    Hi Gurus, Is there any standard report which gives PO No. and PO Creater Name?? Please tell me how can we solve this issue. Thank You

  • Error in PAR file 7.0 after import to NWDS 7.3

    Hi all, Right now am using nwds 7.31 sp05..Please guide me how to edit PAR file from nwds 7.31. and also i would like to know how to change look and feel of the Enterprise portal. Thanks & Regards, Dharmaraj

  • File Attachments are blank - PDF IO Exception

    Hi Everyone, I have a Web Dynpro Java Application form that when submitted generates an Adobe Interactive form along with any attachments and starts a guided procedure. Today I'm experiencing a random error (see below), if I preview the Adobe form be

  • System Update for OS X 10.5.8

    I have a MacBook Pro that was purchased in 2008 and currently just have OS X 10.5.8. I am trying to get 10.8, but cannot seem to find anything below 10.8.1. I need this to update my iTunes so that I can properly update to the iOS 7 on my phone. Help!

  • Snapshot too old when deleting from a "big" table

    Hello. I think this is a basic thing (release 8.1.7.4). I must say I don't know how rollback segments really work. A table, where new records are continuously inserted and the old ones can be updated in short transactions, should be purged every day