How to generate random numbers in a range using random class?

I know how to use Math.random for this, but how would I generate random numbers using the random class?
Say I want a number between 40 and 50, inclusive--how would I do this?
What i have in mind is:
int randomNumber = random.nextInt(max) + min;
where max is 50 and min is 40. Is this correct?

Fredddir_Java wrote:
I know how to use Math.random for this, but how would I generate random numbers using the random class?
Say I want a number between 40 and 50, inclusive--how would I do this?
What i have in mind is:
int randomNumber = random.nextInt(max) + min;
where max is 50 and min is 40. Is this correct?What happened when you generated a couple hundred numbers that way? Did you get all the ints in the range you wanted?

Similar Messages

  • How to generate Serial numbers using JAVA SCRIPT

    how to generate serial numbers(incrementing by 1) using JAVA SCRIPT
    thanking you,
    pola pradeep

    i am afraid that whether ur looking for this. bcoz its a simple for loop
    <script language="JavaScript">
    //count = limit value for u
    for(i=0;i<count;++i){
         alert(i);
    </script>
    or if ur looking for something else, pls mention ur requrment precisely
    aleena

  • How to generate a chirp(linear FM) signal using dds theory in LabVIEW FPGA.

    how to generate a chirp(linear FM) signal using dds theory in LabVIEW FPGA.
    attachment:a sine signal using dds theory. Hope to get some help. Thanks!
    Attachments:
    FPGA DDS SineGen IP.vi ‏42 KB

    you need to increment the "accumulator increment" during the duration of the chirp.  the "accumulator increment" controls the frequency of the DDS cycle.  by increasing it's value, you are increasing the frequency.  the math for increment values follows the same math as determining the frequency to increment value.
    Stu McFarlane
    Viewpoint Systems, Inc.

  • How to generate random numbers in a range?

    Hello. i am having trouble finding out how to generate a random number in a certain range. For example i have an array of 100 elements and i want to access one of the elements between 50 and 60, however i cannot find how to generate a random number between these two values.
    Thanks in advance

    java.util.Random.nextInt(int)
    Note that you can get a number between 0 and (max -
    min), exclusive. Then add min, and you've got your
    number.Obviously you didn't read this. It says to get a number between 0 and (max - min) which is actually what you did. But after that you need to add min. The first step would get a number in between 0 and 5. When you add 20 you'd get a number between 0+20=20 and 5+20=25.

  • How to generate unique numbers

    hi all,
    I want to generate unique numbers always starting from 1 using a single sql query and I dont want to use a sequence and i dont think rownum will be helpful for generating unique numbers in all cases . how to do this ?
    thanks & regards,
    kumar.

    If two users get the MAX from temp, they would be updating with the same value for two different rows.If TEMP is a genuine temporary table, this is not an issue, because the data in a temporary table is only visible within a session.
    The big problem with this approach is the mutating table one: we cannot issue the requisite select statement from a BEFORE INSERT trigger. So this solution is only going to work with a view and an INSTEAD OF INSERT trigger.
    Another, more workable, solution is to use a code control table. This can be (should be) another temporary table, with one row holding one column - next value for TEMP.ID. Normally we would rule out such a solution because it serializes access to the inserted table, but as this is only on a per session basis, it doesn't matter.
    CREATE OR REPLACE TRIGGER tmp_bir BEFORE INSERT ON temp1 FOR EACH ROW
    DECLARE
      ln NUMBER;
    BEGIN
      SELECT nvl(code1.next_id,1) INTO ln
      FROM code1;
      :NEW.id := ln;
      UPDATE code1
      SET    next_id := ln+1;
    END;Beware: coded freehand, so may need debugging.
    Cheers, APC

  • How to generate row numbering over several pages in PAGES??

    How can I generate row numbering over several pages in PAGES??
    e.g. Page1 1-35
    Page2 36-...

    Hi Labrat,
    My suggestion would be to create a Template in the Page Layout mode. This template would have a 1-column Table to present the line numbers and a Text Box for the Body Text. If you want the Line Numbers to stay in alignment with the Body Text, set the spacing for both to Exactly. Set the Table Cell Borders to None. The faint cell borders that you see in the following example are there because I am in View Layout mode. They will not show when printed.
    For my example I have used Format > Advanced > Capture Pages to create a Pull-down +Page option for a Numbered Line Page. You can Capture as many versions of your numbered pages as you like to avoid having to modify the Line Numbers on successive pages.
    Here's my example:
    Regards,
    Jerry
    Message was edited by: Jerrold Green1

  • How to find Delivery numbers for a range of Material Documents

    Hi,
    Could anybody please let me know how to find the delivery numbers from a range of material documents based on a given delivery date.
    Regards
    Kasi

    Hi,
    there is an index table for deliveries by material:
    VLPMA
    Select the delivery numers using the material range from VLPMA.
    Regards,
    Clemens

  • How to generate SIDs for a particular range of data for a DSO ?

    Hi All,
    Please let me know if there is any way to generate SIDs for a particular range of data for a DSO which does not have any SID values. I need this as when i am trying to load data from DSO to InfoCube it's taking a lot of time. When i tried to find the reason behind it, i came to know that most of the time is going in SID creation for the data which is getting loaded. Please share some solution for the same. Thanks...

    Hi,
    Try this.
    Create an internal table and populated it with the values present in the F4 help of the field. Then in AT SELECTION-SCREEN event check the value of the field with the values in the internal table and display the appropriate message.
    Sharin.

  • How to generate jasper report in pdf format using swing

    hi all,
    im new to swing and jasper.. can anybody provide me some example on how to generate the jasper report in pdf format? i will call the reportManager from sessionBean.. below is my code:
    1)delegate:
    public GenerateReportDto generateIntoPdfReport(String fileName, String outputFileName, Map parameters){
    GenerateReportDto generateReportDto = getAuditTrailServiceRemote().generateIntoPdfReport(fileName, outputFileName, parameters);
    return generateReportDto;
    2)sessionBean:
    public GenerateReportDto generateIntoPdfReport(String fileName, String outputFileName, Map parameters){
    //Map parameters = new HashMap();
    ReportManager reportManager = new ReportManager();
    3)ReportManager()
    public void generateIntoPdfReport(String fileName, String outputFileName, Map parameters) {
              Connection conn = null;
              try {
                   conn = dataSource.getConnection();
                   //Generate the report to bytes
                   File reportFile = new File(fileName);               
                   byte[] bytes =
                        JasperRunManager.runReportToPdf(
                             reportFile.getPath(),
                             parameters,
                             conn
              //conn.close();
              //Write the bytes to a file
              ByteBuffer buf = ByteBuffer.wrap(bytes);
              File file = new File(outputFileName);
              // (if the file exists)
              boolean append = false;
              // Create a writable file channel
              FileChannel wChannel = new FileOutputStream(file, append).getChannel();
              // Write the ByteBuffer contents; the bytes between the ByteBuffer's
              // position and the limit is written to the file
              wChannel.write(buf);
              // Close the file
              wChannel.close();
              } finally {
                   if (conn != null) {
    conn.close();
    Any help would be highly appreciated. Thanks in advance

    Hi ,
    One 'simple' way is by using the DBMS_SCHEDULER db package and the procedure CREATE_JOB(....) using as job_type the value 'EXECUTABLE'...
    Read for further info in 'PL/SQL Packages and Types Reference'.
    If you have access to OEM ... you can configure this there using wizard.....
    Other way is to use the External Procedure call capabiblity of Oracle DB Server...:
    http://www.oracle.com/pls/db102/ranked?word=external+procedure+call&remark=federated_search
    My greetings,
    Sim

  • How to generate finite cycles of sine wave using daq mx in vc++

    Hi,
    How to generate finite cycles of sine wave or for finite duration in vc++ using hardware timer without any sleepfunction in the code.
    Thanks & Regards,
    satya

    Hello Elizabeth,
    Thanks for the response.
    1) I am using NI 6040E PXI.
    2) I am using NI-DAQMx 8.3
    3) Measurement Studio is 6.0.0.105
    4) Operating system is Windows XP.
    I want to generate sine wave for finite duration previously in traditional daq there was function called wave_op.In which we can mention number of cycles of sine wave we wanted to generate. That function is not available in DAQMx so we have to use sleep function to generate finite period. Any hardware control function to control generation of finite cycles please let me know.
    Thanks & Regards,
    satya

  • How to count the days between Date Range using OO ABAP?

    hi experts,
            i want to count the days between Date Range using OO ABAP for that  which class and method  can i use?.
    Thanks,
    Mahesh.

    Not sure I understand the requirement for it to be OO, but you could always write your own (i.e. use this):
    REPORT zz_date_diff.
    CLASS date_diff DEFINITION.
      PUBLIC SECTION.
        METHODS diff IMPORTING     i_date_fm TYPE d
                                   i_date_to TYPE d
                     EXPORTING     e_days    TYPE i.
    ENDCLASS."
    CLASS date_diff IMPLEMENTATION.
      METHOD diff.
        e_days = i_date_to - i_date_fm.
      ENDMETHOD."
    ENDCLASS."
    DATA: g_ref TYPE REF TO date_diff,
          g_days  TYPE i,
          g_date_fm  TYPE d VALUE '20080101',
          g_date_to  TYPE d VALUE '20090101'.
    START-OF-SELECTION.
      CREATE OBJECT g_ref.
      CALL METHOD g_ref->diff
        EXPORTING
          i_date_fm = g_date_fm
          i_date_to = g_date_to
        IMPORTING
          e_days    = g_days.
      WRITE g_days.

  • How to import .jar files in order to use the classes within this file

    hello guys,
    I'm just wondering how can i import .jar files in order to uses the classes within this file.
    let's take an example:
    i have a folder in which I have many .jar files which contain classes to be called. the full path of this folder is set in the Classpath inside the enviroment variables.
    so does anyone have any idea how can i import these .jar files so i can use the classes?
    thank you.

    Hi,
    My problem is that: I created a Serializable class in a project. And I added this project (first project) to another project (second project). First project is appearing in the second project' s Libraries folder. No problem. I want to create a jar file from second project. i.e. I want to Build second project (I use NetBeans IDE). I am using Build Main Project tab under Run. It is falling out. I am finding it second project' s jar file under its folder. I am clicking on it. But it is NOT WORKING. Do you know WHY. Could you help me please?
    Thanks,

  • How to generate catlog numbers for a material

    hi,
         how can we generate catlog number for a material ?
    my company runs on the catalog numbers .
    thanks
    mmn

    Hi
    IS your company running on IS-Retail?
    Regards
    Ramakrishna

  • How to generat code numbers automatically?

    Dear members,
    i have 3 tables with code no which are primary key and char datatype.
    the first code number is 2 characters,
    then the 2nd code number is 5 characters
    then 3rd code number is 9 characters.
    the first table's code numbers are manually defined. 10, 20, 30 and so on.
    but the requirement is to generate the 2nd table's code number automatically by fixing the 1st tables 2 characters on the left and then 10001, 10002, 10003, 10004 and so on.
    and like this the 3rd table's code number to be generated by fixing the first 5 characters on the left from the 2nd table and the 4 characters on the right 100010001, 100010002, 100010003, 100010004 and so on.
    for example:
    FIRST TABLE 2ND TABLE 3RD TABLE
    10 10001 100010001
    10002 100020001
    20 20001 200010001
    20002 200020001
    30 30001 300010001
    30002 300020001
    How can do this job?
    i issue the following query.
    declare
    v_2nd_code_no char(5);
    begin
    select max(2nd_code)+1 into v_2nd_code_no from 2nd_table;
    select first_code_no||v_2nd_code_no into :blk.item from dual;
    end;
    it give the following error.
    ORA-06502: PL/SQL: numeric or value error string
    now how can i do this job.
    thanks in advance.
    Muhammad Nadeem
    [email protected]

    Muhammed,
    I think you should reconsider your design. Duplicating data into other columns will give you update headaches, uses extra storage, and fool the optimizer, and maybe others will point out more disadvantages.
    In my opinion your table should look like this:
    code1 number(2,0)
    code2 number(3,0)
    code3 number(4,0)
    Please note that they are numbers! Using numbers for numbers is the right way for not fooling the optimizer. Before executing a query, Oracle determines the access path to retrieve all information, based on statistical information on all the tables,columns and indexes involved. If you issue a query with a predicate like:
    code3 between '100019999' and '100020000'the optimizer will think there are numerous strings between the two "numbers" and will maybe head towards a full table scan, or at least think there are thousands of values between the two.
    Now, if in your application you want to get a nicely displayed number with leading zeros and all, you just use:
    rpad(to_char(code1),2,'0') || rpad(to_char(code2),3,'0') || rpad(to_char(code3),4,'0')Regards,
    Rob.

  • How to generate PDF file from HTML file using Acrobat API's

    Hi,
    I want to generate a PDF file from an HTML file on server side(C# .Net).
    Their is a COM interop called "AcrobatWeb2PDF" availaible but could not find any document regarding how to use it.
    I cant use "Adobe live cycle PDF Generator" as we just have license for Adobe Acrobat 8 Professional.
    Please help...
    Thanks and Regards,
    Anand Mahadik.

    > It is hard to believe that Adobe doesn't provide a toolkit for generating PDF files, so many web based applications have vector based content that needs to be converted to PDF!!!!
    They do, it's just not free (A company in business to make money? I'm sure IBM would never think this way... ;)). As mentioned you have Adobe LiveCycle PDF Generator, which you can customize and extend with Java. You also have the Adobe PDF Library SDK, which is written for use with C/C++ although if you license it from Datalogics (the only company in NA Adobe allows to license the PDF Library) you will also get .NET and Java interfaces (part of the DLE - DataLogics Extensions).
    > There must be a way to generate PDF dynamically on a server or from Javascript!
    JavaScript? Not really, no. As far as I'm aware JavaScript has no file system access capabilities without some form of intermediary (like sending the data to a webservice that writes it out to file). How would you create a PDF file with JavaScript?
    The PDF Standard is also in ISOs hands now (ISO 32000-1:2008), it is no longer owned by Adobe - you can download a copy of the specification from them and write your own library based on that as well.

Maybe you are looking for

  • How to open animated .GIF files in Photoshop CS3 and newer

    Q: Since ImageReady is long gone from Photoshop, how can I open animated GIF files in Photoshop CS3 and newer? A: File -> import-> video to layers. In the dialogue box type "*.*" to show all file types. Select your GIF file and which frames to import

  • GRC 10.1 Integration with PI 7.4 and BODS?

    Hi Experts, As per our system design we have to configure workflow for termination of users in SAP PI 7.4 and BODS system through GRC 10.1. Can someone share the connection steup instruction for the above systems? Thanks, Trinetra

  • Identifying the correct MIME type for file uploads

    How does Apex identify the MIME type of an uploaded file? I have a page that uploads a file and accesses it via APEX_APPLICATION_FILES. That works fine. The problem is that, for certain file types, the mime_types column is "application/octet-stream"

  • Automatically add to mobileme gallery

    If a smart folder is synced with mobileme gallery, does its contents change the same as if it were the smart folder itself. For example, if sync a smart folder containing >4* from a project then add more images and rate them >4*, will they automatica

  • Default Printer not sticking in 10.4.10

    This is something I've just noticed in the last few days. I have three printers plus the Adobe PDF printer in my printer list: an Epson SC Photo 2200 with all of its variants, an Epson SC 740, a LaserWriter IIg (in great shape), and the PDF virtual p