How to use Math.random() to generate an integer within a range

How can I generate a random integer from 1 to 10 using the Math.random() method?
Thanks.

Then why do i get this compile-time error?
found   : double
required: int
                    matrix[i][j] = (int) 11 * Math.random();
matrix is an array of integers:
String colNumStr = JOptionPane.showInputDialog("Please specify the number of rows");
    String rowNumStr = JOptionPane.showInputDialog("Please specify the number of columns");
    int rowNumInt = Integer.parseInt(rowNumStr);
    int colNumInt = Integer.parseInt(colNumStr);
    int [][] matrix = new int [rowNumInt][colNumInt];

Similar Messages

  • Using a random image generator in a frameset [was: "I'm a photographer, not a web designer!"]

    I've been designing my own website for some years now using dreamweaver.  I love the ease of use and simplicity it offers, however I know nothing of designing web pages.  I know what I want but I just don't exactly always know how to get there.  I am currently trying to have a random image generator on my landing page, which is a frameset.  I've tried several codes that I've found online and have had no success, at all mind you, with any of them.  I'm sure that I am doing something very simple wrong with my design but just can't figure it out.  Unfortunately I am a photographer which makes me a visual person, so yes, if you can help me you'll have to draw a picture for me, or at least hold my hand and walk me through the steps.  Sorry, I know I'm high maintenance.
    My site is all frameset based.  I have a 'mainFrame' that all other links in the other frames load to.  So I am assuming that my code for the image generator should go in the body of the mainFrame.  I have even copied and pasted all the code from some of the help I've found, downloaded a cfm to try, all to no avail.  Con someone spell it out for me, or better yet, draw me a picture.
    [Subject line edited by moderator for clarity]

    My site is all frameset based.
    That's a tragedy.  Frames, once popular in the 90's are almost never used anymore.  In fact, the W3C saw fit to drop frameset support from HTML 5.
    Why Frames are Evil:  http://apptools.com/rants/framesevil.php
    Instead of Frames or Framesets, consider using Templates (DWTs) or Server-Side Includes (SSIs)
    Guidance  on when to use DW Templates, Library Items and SSIs -
    http://www.adobe.com/devnet/dreamweaver/articles/ssi_lbi_template.html
    Below are several DHTML image rotation/slideshow scripts.  Just pick one and follow the instructions.
    http://www.dynamicdrive.com/dynamicindex14/index.html
    Good luck,
    Nancy O.
    Alt-Web Design & Publishing
    Web | Graphics | Print | Media Specialists
    www.alt-web.com/
    www.twitter.com/altweb
    www.alt-web.blogspot.com

  • How to use Flex Builders Auto Generated CFCs

    OK. Not only have I already gone to a 4 day flex training,
    have an advanced coldfusion certification and work with 3 coworkers
    who have done the same...none of us can figure out how in the heck
    the flex builder's autogenerated cfc's are to be used. No big deal
    on the fact that this might be something we simply are encountering
    for the first time, but the complete and utter absence of a single
    piece of example code or documentation stating how to use this code
    correctly is very very very very irritating.
    Can anybody, share with me anything about how these CFCs are
    to be used correctly. For example. We are using the wizard to
    generate an "Active Record CFC" set of cfc's for an example table
    contain four fields. We have a data grid that is now populated by
    the "getAllAsQuery" function....we would like to implement the
    feature of making this dataGrid updateable. We know how to pass
    data back and forth and yes we could write our own CFC to do
    this...but having it autogenerated is a really neat option...but
    the question remains....how does one use them!!!
    Any help would be much appreciated. Thanks in advance!

    Hi there, what's your name by the way?
    What is a VO or DTO, and why would you use it?
    This was copy from the Java world, so it's a very OOP principle, basically in the OOP world everything is a class that has methods and properties, and you represent everything with classes, a VO is just that a class that represents an entity in your app. You use it for a few reasons in my opinion:
    It allows you to pass strongly typed data between different layers in your app.
    It's more verbose, it's a good OOP practice, and also makes debugging and reading you code easier.
    It allows easy data type conversion between CF and Flex.
    You obviously know how to use the wizards, after you select your table and open the wizard you'll see three different CFC types, if you're using LCDS then select that type if you don't I'll recommend you to go with BEAN/DAO. In Flex Builder you can create a folder link to a system folder, so if you create a folder named MyCFCs and you set this virtual folder to be hold inside c:\ColdFusion8\wwwroot every file that you put in this folder will be place in c:\ColdFusion8\wwwroot so you don't have to manually copy those files.
    In this wizard you'll see CFC folder in there you can select your virtual folder, you'll see below the CFC package name this is extremely important to be set right, what is the CFC package name? Basically it's the same folder structure where your CFCs will be located for instance let's say you're gonna place the files in this folder structure c:\ColdFusion8\wwwroot\com\myPersonalDomain\ so your CFC package name will be com.myPersonalDomain.
    You'll probably also would like to enable the option: Create an ActionScript value object in addition to CFCs, the folder where you place this file have to mimic the CFCs folder structure so for an instance you'll have to save inside your src folder, inside a folder com, an finally inside a folder myPersonalDomain . src/com/myPersonalDomain, and the AS Package name should be the same as the CFC.
    Once you're done and click finish, you'll see for files created, one of the the AS VO , and three CFCs.
    yourDataTable.CFC
    This is a CFC that creates the VO or DTO in CFC, it has the same properties definition that the AS version has, also the setters and getter for every property.
    yourDataTableDAO.CFC
    This CFC contains all the code that handles the database access it a could be an insert, update delete or just a read query.
    yourDataTableGateway.CFC
    This is a bridge between your Flex app and your CFCs, it contains a set of methods commonly use when you access a DB, this CFC invocates the methods in the yourDataTableDAO.cfc and returns an object or an array of objects of yourDataTable.CFC type to Flex.
    In Flex what do you have to do in order to use VOs?
    Add a reference to yourDataTable.as class
    Create a remote object.
    Create the event handler(s)
    Make a call to the remote object.
    <mx:Script>
         <![CDATA[
                   import com.myPersonalDomain;
                   import mx.controls.Alert;
                 import mx.rpc.events.ResultEvent;
                  private var myDummyVar:myDataTable;
              private function myEventHandler(e:ResultEvent):void{
                   //do Something
                   trace(event.result.toString());
         ]]>
    </mx:Script>
    <mx:RemoteObject id="myRO" destination="ColdFusion"
    source="com.myPersonalDomain.myDataTableGateway">
         <mx:method name="getAll" result="myResultHandler(event)"
    fault="Alert.show(event.fault.toString())" >
    </mx:RemoteObject>
    <mx:Button label="Call CF" click="myRO.getAll()" />
    Well I hope this would help you, I'm kinda tired this has been by far the largest post I've written.

  • How to use math formula on waveforms

    Hi all,
    I'm trying to create a program that can use math scipts, formulas etc on waveforms. I've done it for one signal, but I don't know how to change work on 2 or more signals;/ Let's see exampe: one channel is voltage, the second is current and I want to see both of them and as a third signal power so I'm writting formula ch3=ch1*ch2. Another example: I've signal which represents speed of starting motor (500 points) but I need only few points so the formula will be: ch1(20:120) and I have points from 20 to 120. Is it possible to do it? I can't do it using blocks cause I don't know which signal means what... so ch1 can be voltage, ch2 speed, ch3 current ch4-torqu etc. I know that I can cut a part of signal by subarray or subwaveform but it must be done by formula to use (for example) something like that:
    ch1(1:20)=0 <- replace all point from 1 to 20 of ch1 by 0
    ch2(50)=40 <-replace point 50 of ch2 by 40
    ch3=ch1*2 + ch2 <- do this operation but first do both above this one.
    Is it possible? or it's to complicated?
    I attached my vi which is working for one selected signal (I don't want to select it... but I don't know how to do it;/) and signal that I'm using to check how it's work
    Thanks
    Mike
    Attachments:
    Archive.zip ‏134 KB
    math formula.vi ‏152 KB

    I've upgraded it a little and it works with 2 signals but very sensible;/ formula must have this construction: c3= ... , both of signals must be switched on, there's no way to use part of signal (e.g.c1(21:54) ) and I can't use 2 rows (something like this: c3=c1*c2; c3=c1 doesn't work);/ additionally I wanted to have possibility to use all of signals as input and all of them as output
    Attachments:
    math formula.vi ‏183 KB

  • How to use application builder to generate installation disk without compiling the the support files?

    Hello,
    What I am trying to do is to use LV application builder generating an installation disk without compiling the support files. I mean:
    the support fils like the help files are located on a different directory , for example, installation disk is D drive, help file directory is: D:\Help\...,  not compiled in the installation Data set.
    So,  when the installation disk is running, it only copy this directory file into the destiny directory. Of course, we can write a different bat file to do this. However, beside this method, is there any way, like using LV application builder to do this without writing a batch file.  Any suggestion will be appreciated.

    For LabVIEW 7.1, this can be done in a few short steps. First, add your help file as a support file in the Application Builder. Then go to the Installer tab, choose to create an installer and click on the Files button at the bottom. From this dialog (shown below), you can specify the destination for each component in your install package. If you have added your help file as a support file, it will show up in the Files in Installation list. Click on your help file to highlight it. You can now choose where to install the file to by specifying an installation destination and a subdirectory. The default subdirectory is called data, but if you want to change that, just type in a new subdirectory name as I have done below:
    Hope this helps!
    Message Edited by Jarrod S. on 01-23-2006 10:17 AM
    Jarrod S.
    National Instruments
    Attachments:
    Support Files.JPG ‏31 KB

  • How to use the random generator in java

    hey peeps, this is the class in which i am trying to implement the random generator in;
    public class Matchlist
        private studentdetails sd = new studentdetails();
        /** matchList StringBuilder stores the match list in progress */
        private StringBuilder matchList = new StringBuilder();
        private int loop = 0;
        private int matches = 0;
        public Matchlist()
            sd.createstudentdetails();
        /** Method to create the actual match list, returns the list as a string */
        public String CreateMatch()
            int g;
            int y;
                for (g = 0; g < 4; g++)//g = game
                    for (y = 17; y > -1; y--)//y = green house
                        /** Check to see if the game is empty */
                        if (sd.getgh(y).getGame(g).equalsIgnoreCase(""))
                            for (int x = 0; x < 18; x++) //x = yellow house
                                if (sd.getyh(x).getGame(g).equalsIgnoreCase(""))
                                    if (sd.getgh(y).getC_lass() != sd.getyh(x).getC_lass())
                                        /** Check to see if the person has played the other person */
                                        if (sd.getgh(y).checkPlayed(sd.getyh(x).getName()) == false)
                                            /** Set the game to the name of the opponent played */
                                            sd.getyh(x).changeGame(g, sd.getgh(y).getName());
                                            sd.getgh(y).changeGame(g, sd.getyh(x).getName());
                                            /** Build the match list step by step using append with \n at the end to create a new line */
                                            matchList.append(sd.getyh(x).getName() + " vs " + sd.getgh(y).getName() + "\n");
                                            matches++;
                                            break;
                /** Convert the stringbuilder into an actual string, then return it */
                String completeMatchList = matchList.toString();
                System.out.println(matches);
                for (int i = 0; i <18; i++)
                    sd.getyh(i).getEmptyMatches();
                    sd.getgh(i).getEmptyMatches();
                return completeMatchList;
        }what i dont understand is how to implement it to pick my matches at random using the http://java.sun.com/j2se/1.4.2/docs/api/java/util/Random.html java tutorials from here
    regards

    How to use Random ?
    First you open API then you read it, then you use it.
    You mention you try to use it but i just see a horrible nested for for for if if if loop.
    Restructure code and question and maybe it makes more sense.
    Edited by: pgeuens on 10-mrt-2008 22:58

  • Applescript: how to record and return how many times a number appears when using a random number generator

    I create one rng and repeat another rng that many times like so:
    set x to (random number from 0 to 250)
    repeat x times
      set rn to (random number from 1 to 10)
    end repeat
    now what i would like to do is record and return how many times 'rn' comes up with one particular number. Any ideas?

    You could set up a list and increment the contents of a particular index each time it comes up, for example:
    set how_many to {0, 0, 0, 0, 0, 0, 0, 0, 0, 0} -- 1 thru 10
    set x to (random number from 0 to 250)
    repeat x times
      set rn to (random number from 1 to 10)
      set item rn of how_many to (item rn of how_many) + 1
    end repeat
    return how_many

  • How to use regular expressions to generate test data ?

    Hi
    Someone can help me on what I have to do in order to create test data with regular expressions ?
    For example, I want to introduce a random telephone number (XXX-XXXX) in the phone number Form Field, I want to create the phone number using regular expressions in order to test different values in each playback of the script.
    I don't want to use VB or vbscript in e-tester, I'm just trying to do this with e-load nav editor and e-load
    Thanks a lot

    Hi and thanks for your answer!, it's a great trick ^_^
    I'm doing a research on how to improve the execution speed of the scripts in e-load, so actually I'm trying to avoid the use of databanks and VB code also.
    I was expecting that maybe e-load, e-load nav editor or e-tester can automatically generate test data via Regular Expressions. Someone Knows if this is possible ?
    Also can anyone tell me what the option "Automatically Generated (complex)" means ? I think that this will help me a lot
    *you can find this option in e-load Nav Editor when you select a parameter in the tree view, then go to the  "type" listbox in the properties pane, there you will find this option and some more options like :"Databanked variable", "Custom Dynamic Value", "Function".. etc.
    Thanks again

  • How to use the column names generated from Dynamic SQL

    Hi,
    I have a problem with Dynamic SQL.
    I have written an SQL which will dynamically generate the Select statement with from and where clause in it.
    But that select statement when executed will get me hundreds of rows and i want to insert each row separately into one more table.
    For that i have used a ref cursor to open and insert the table.
    In the select list the column names will also be as follows: COLUMN1, COLUMN2, COLUMN3,....COLUMNn
    Please find below the sample code:
    TYPE ref_csr IS REF CURSOR;
    insert_csr ref_csr;
    v_select VARCHAR2 (4000) := NULL;
    v_table VARCHAR2 (4000) := NULL;
    v_where VARCHAR2 (4000) := NULL;
    v_ins_tab VARCHAR2 (4000) := NULL;
    v_insert VARCHAR2 (4000) := NULL;
    v_ins_query VARCHAR2 (4000) := NULL;
    OPEN insert_csr FOR CASE
    WHEN v_where IS NOT NULL
    THEN 'SELECT '
    || v_select
    || ' FROM '
    || v_table
    || v_where
    || ';'
    ELSE 'SELECT ' || v_select || ' FROM ' || v_table || ';'
    END;
    LOOP
    v_ins_query :=
    'INSERT INTO '
    || v_ins_tab
    || '('
    || v_insert
    || ') VALUES ('
    || How to fetch the column names here
    || ');';
    EXECUTE IMMEDIATE v_ins_query;
    END LOOP;
    Please help me out with the above problem.
    Edited by: kumar0828 on Feb 7, 2013 10:40 PM
    Edited by: kumar0828 on Feb 7, 2013 10:42 PM

    >
    I Built the statement as required but i need the column list because the first column value of each row should be inserted into one more table.
    So i was asking how to fetch the column list in a ref cursor so that value can be inserted in one more table.
    >
    Then add a RETURNING INTO clause to the query to have Oracle return the first column values into a collection.
    See the PL/SQL Language doc
    http://docs.oracle.com/cd/B28359_01/appdev.111/b28370/returninginto_clause.htm#sthref2307

  • How to use a random number equal another number. (with my source code)

    hi, i'm having trouble with this assignment.
    3. Determine how many times a die must be rolled in order to
    win a prize. (This represents one trial.) Print this value to a
    text file.
    4. Conduct at least 1,000 trials.
    5. Read the data back in from all of the trials.
    6. Calculate the average number of times a die must be rolled in order to win a prize.
    7. Print the result to the screen
    This is what I have so far.
    But I get a "int cannot be dereferenced" error
    * Write a description of class BottleCapPrize here.
    * @author (your name)
    * @version (a version number or a date)
    import java.io.IOException;
    import java.io.PrintWriter;
    import java.util.Scanner;
    import java.util.Random;
    import java.io.File;
    public class BottleCapPrize
    public static void main (String [ ] args) throws IOException
    PrintWriter outFile = new PrintWriter(new File("bah.txt"));
    Random randomGenerator = new Random();
    int random = randomGenerator.nextInt(5);
    int count = 0;
    for (int loop = 1; loop <= 1000; loop++)
    if(random.equals("3"))
    outFile.println("Congratulations, both pairs matched.");
    count++;
    outFile.close ( );
    }

    And the random generator can only choose a 1 or 2 or 3 or 4 or 5. This is then randomly chosen 1000 times like 400 2s and 200 5s for example.I think you have still to appreciate that the task is not to roll a dice 1000 times and see how many of each number you get.
    Tackle it one step at a time:
    3. A - Determine how many times a die must be rolled in order to win a prize. (This represents one trial.)
    B - Print this value to a text file.
    Even the first part of the problem can be broken down into two parts. I strongly suggest to get step 3A working correctly before you move any further. Notice that this step does not involve 1000 rolls of the dice. Rather it asks you to roll the dice as many times as needed until you get a three. Start there: write a method that does no more than report the number of times it had to roll the dice in order to get a three.
    import java.util.Random;
    public class BottleCapPrize
        public static void main (String [ ] args) throws IOException
            Random randomGenerator = new Random();
            int count = 0;
             * Your code here.
             * At the end of it count should be equal to the number of
             * dice rolls it took to get a three.
            System.out.println("It took " + count + "dice rolls to get a three");
    }Once you have this method working correctly - that is you run it lots of times and it agrees with what you find experimentally with an actual dice - then you can move on to saving this result to a file (step 3B). The steps of the assignment provide a framework that makes sense - follow them one at a time.
    but only thing is that the random number is all a certain number.That's a fairly major defect in a randomly generated number ;). Read the API documentation for the [nextInt(n)|http://java.sun.com/javase/6/docs/api/java/util/Random.html#nextInt(int)] method. It should be clear that this is the method that randomly generates a number. So if you want lots of randomly generated numbers (rather than one randomly generated number lots of times) then you have to call this method lots of times. A call to nextInt(n) is the programming equivalent to rolling a dice.

  • How to use math symbols in Pages

    How can I find math symbols in Pages?
    Do I need additional Software or is there a possibility as in Microsoft Word?

    You can find some math symbols in Pages if you go to Special Characters. Open Pages, go to Edit menu (on the menu bar) > Special Characters, and choose math symbols in the sidebar, so you will be able to add a symbol double-clicking the symbol.
    However, it may not include all symbols. In this case, you will have to use other third-party applications

  • How to use pdf annotation data generated by Digital Edition to different Pdf reader?

    Hi,
    I am working on an application which is suppose to use Adobe Digital Edition PDF annotation data in another pdf reader.
    Using Digital Edition Annotation Data we need to generate highlights and notes.
    My question is : How we can read this Adobe Digital Edition annotation data to generate highlight and notes in different reader.
    E.g of annotation data:
    http://codebeautify.org/xmlviewer/32b3b7
    Thanks
    Mrityunjay

    HI,
    Try this Standard program
    RSTXLDMC  -->    Uploading TIFF Files to SAPscript Texts
    Regrads,
    S.Nehru

  • How to use single Timer to generate PWM PULSE, Pulse ON time measuremen​t, Event time measuremen​t1,Event time measuremen​t2

    Hi,
    I am planning to use a single Timer to generate PWM PULSE, Pulse ON time  measurement, Event time measurement1,Event time measurement2 some one please suggest me how can I achive this.
    Thanks in advance..
    Michael

    Hi Michael,
    It would be really good to understand your application a little more so that any specific needs that you have may be met. In the meantime, I would also suggest searching on ni.com for "pwm" or other keywords that relate to your application. You will see a faceted navigation on the left side that allows you to narrow your search for example code, tutorials, etc.
    Please post back with more information and the community will be able to help out with suggestions.
    ni.com search for "pwm"
    Mark E.
    Precision DC Product Support Engineer
    National Instruments
    Digital Multimeters (DMMs) and LCR Meters
    Programmable Power Supplies and Source Measure Units

  • How to use the ITS Theme generated by ITS Theme generator of Portal

    Hi,
    I have generated an ITS Theme using ITS Theme generator of Portal. I exported the theme . It is a zip file containg some xml files and two zip files - Portal and ITS. When I unzip ITS.ZIP I have webgui folder under which there is ma and sa.These folders have various images.
    Now how do I apply the generated theme.
    Regards,
    Harish

    Hi Edgar,
    Thanks for responding. Yeah I looked at that documentation earlier and these are the activities we have done so far:
    1. Using ITS theme generator in portal, generated ITS theme for our custom portal theme.
    2. Verified from theme export that ITS.zip contains all relevant images, stylehsteets etc for our custom theme.
    3. Even after this, when we preview transaction iViews from portal to execute a transaction on ECC system those iViews pick up default SAP theme but not our custom theme.
    4. After looking at the OSS notes mentioned in help documentation, we used ~webTransactionType, ~design & ~designBaseUrl parameters in iView properties but no luck. Actually these parameters get ignored - even if we put invalid host name in designBaseUrl it doesn't throw any error.
    We use EP 7.0 SP 17 and ECC 7.01 Ehp4 with integrated ITS. When we generated the theme using ITS theme generator in portal, we tried with service as webgui and also sap_generate but the iViews pick up only default SAP theme. How do we point ITS webgui and transaction iViews to custom portal theme?
    Thanks for your help!
    Veda

  • Bridge CC / How to use all cores to generate preview images?

    Hi!
    Is there anyway to tell Brdige, that it should use all my cores to generate the preview images?
    Actually it uses only 25% of my CPU performance. I've a Intel Core i7-2600 CPU @ 3,4 GHZ, with four cores and enabled hyperthreading, also eight virtual CPUs.
    At least it could be FOUR times faster, if it would use all available cores, but so I get one preview per second (12 MP RAWs). So I've to wait in case of 1.000 RAWs round about 15 minutes. If would use all CPUs, which are available, it could increase speed up to 4 minutes. More then 10 minutes saved.
    As there any chance, or does Adobe have no interest, like it has no interest to speed up LightRoom?
    If there is any chance, I would be very pleased.
    Thanks

    It's really frustrating:
    While Adobe Camera RAW is able to process different images in parallel and speeding up the process.
    Other teams of Adobe are still telling me, that it's impossible to process several images in parallel and speeding up the Bridge thumbnail and preview generating process:
    http://feedback.photoshop.com/photoshop_family/topics/bridge_cc_how_to_use_all_cores_to_ge nerate_preview_images?rfm=1
    I do not get it. :-(

Maybe you are looking for

  • How do I set up multiple users on itunes.

    My two kids have my old phones and I want to set up apps and music for them and keep separate from mine...they are too young to have their own itunes account. Can anyone point me in the right direction

  • Sound but no video after going to Quicktine 7.1 - RESOLVED

    Hi All, I posted this as an issue last night but have since figured out the problem. It seems Quicktime 7.1 adds a feature in the control panel under the advanced tab. For DirectX playback of video, the checkbox: Enable Direct3D video acceleration wa

  • I can't see other people's pics on BBM or put my own up.

    I just got a Curve 8530, and in BBM I can't seem to put in a picture, I also cannot see my friends pictures. A few of them that have blackberrys (both older and newer models) have tried to solve the problem in my phone and it seems like my phone is m

  • BI content is displayed or not.

    Hi all, I want to know about the status of BI_content. That is whether BI content is deployed in the particular system.How is it possible to see the status of the BI content Regards Vijay

  • Weird, system-wide text misalignment

    I've got this issue that shows symptoms in a couple of places. First, it affects Dashboard. A prime example of this is the large numeral denoting the current date in the calendar widget. So today it's a large "7". The number itself has shifted upward