How do i save random numbers?

below is the coding for random numbers
public class Random {
public static void main(String[] args) {
java.util.Random rand = new java.util.Random();
for (int i = 0; i < 20; i++) {
System.out.println(rand.nextInt(10));
}how do i save the random numbers?????

That was a quick sample. I'm guessing you're not too familiar with java. I expect the error was because you havn't imported the java.io library.
import java.io.*;
public class tester {
  public static void main(String args[]) {
    try {
      PrintWriter out = new PrintWriter(new FileWriter("tmp.txt"));
      java.util.Random rand = new java.util.Random();
      for (int i = 0; i < 20; i++) {
        out.println(rand.nextInt(10));
      out.close();
    } catch (IOException ioe) {
      ioe.printStackTrace();
}This will compile and run. Notice how you have declared your Random class using java.util.Random? You could have imported java.util.* or java.util.Random then used the declaration 'Random rand = .....' instead (like how i've declared the PrintWriter).
Rob.

Similar Messages

  • How do I save my numbers spreadsheets as Excel as I could in previous version of Numbers?

    I updated to MAvericks and right after got a not that iWorks had updates, now my Numvers does not have key functionality that I need in order to send spreadsheets and worknooks back and forth with companies I work with. How do I save my numbers spreadsheets as Excel as I could in previous version of Numbers?

    Under the File menu select Export. You'll find Excel as one of the export options there.

  • How to generate unique random numbers

    Hi All,
    I am wondering whether there is already a random library or built-in function available in Java to produce some random numbers between certain ranges that are not repetitive. Let's look at a common examples as follows:
    Random diceRoller = new Random();
    for (int i = 0; i < 10; i++) {
      int roll = diceRoller.nextInt(6) + 1;
      System.out.println(roll);
    }My understanding from this approach is that it allows the same number to be repeated over and over again. However, I would like to find out how to continue generating random numbers from remaining ones that haven't been generated earlier.
    Using the above example to illustrate my intention:
    1st random number generated - possibility of 1 - 6 showed up. Say 5 is picked.
    2nd random number generated - possibility of 1, 2, 3, 4, 6 only. Say 2 is picked.
    3rd random number generated - possibility of 1, 3, 4, 6 available. Say 1 is picked.
    4th random number generated - possibility of 3, 4, 6 left. Say 6 is picked.
    5th random number generated - possibility of 3, 4 remains. Say 4 is picked.
    Any assistance would be much appreciated.
    Many thanks,
    Jack

    htran_888 wrote:
    Hi All,
    I am wondering whether there is already a random library or built-in function available in Java to produce some random numbers between certain ranges that are not repetitive. Let's look at a common examples as follows:
    Random diceRoller = new Random();
    for (int i = 0; i < 10; i++) {
    int roll = diceRoller.nextInt(6) + 1;
    System.out.println(roll);
    }My understanding from this approach is that it allows the same number to be repeated over and over again. However, I would like to find out how to continue generating random numbers from remaining ones that haven't been generated earlier.
    Using the above example to illustrate my intention:
    1st random number generated - possibility of 1 - 6 showed up. Say 5 is picked.
    2nd random number generated - possibility of 1, 2, 3, 4, 6 only. Say 2 is picked.
    3rd random number generated - possibility of 1, 3, 4, 6 available. Say 1 is picked.
    4th random number generated - possibility of 3, 4, 6 left. Say 6 is picked.
    5th random number generated - possibility of 3, 4 remains. Say 4 is picked.
    Any assistance would be much appreciated.If it is your school assignment then you have the answer above (List & the lists length).
    (You might want to look at Collections)

  • How do I save a Numbers spreadsheet as an earlier version

    I have just upgraded to Yosemite from Snow Leopard.  I have a spreadsheet which I have sent to a third party and they are unable to open it as they are on an earlier version of Numbers.  How do I save my spreadsheet in the format which they can open?

    In the current version of Numbers you can use the File Menu Export item to save to a Numbers 09 compatible file.

  • How do I generate random numbers from a list of numbers without repeating any number

    I am trying to generate a list of random numbers without any repeating numbers.  For example say the list is from 1 to 15, how do I randomly generate a list of numbers using each number only once?

    pb,
    You can build a randomizer by making a 2-column table with 15 rows. In Column A, Fill with the numbers 1 to 15. In column B Fill with RAND(). Then sort on Column B. There will now be a randomized list of the numbers from 1 to 15 in Column A. You can copy this random list and use it in your application.
    Jerry

  • How do i save a numbers doc under a different name

    I'm trying to save a numbers document under a different name.  I could change it easily yesterday but it's not working today?

    What version of OS X and Numbers are you using?
    If you are working under Lion and the latest version of Numbers use File > Duplicate and then Save.
    Mario

  • How can I save a Numbers spreadsheet as a tab delimited file?

    Okay, I would like to save a Numbers spreadsheet as a tab delimited file. But of course I can't do that, since Numbers only saves as a comma separated values file.
    Plan B: I can open up a CSV file created by Numbers in TextEdit, and I would like to Find and Replace all the commas with tabs. So I open up the Find window, enter a comma under Find, but of course when I put the cursor in the Replace blank and hit the Tab key, it just goes to the next blank instead of giving me a Tab.
    Is there a way I can get a Tab into that blank so I can replace all the commas with tabs?
    --Dave

    Hello
    When we use TextEdit as I described, rows are separated by Returns.
    It appears that your program requires LineFeeds.
    Here is a neat soluce.
    Save this script as an Application Bundle.
    --\[SCRIPT tsv2csv]
    (* copy to the clipboard a block of datas separated by tabs
    run the script
    You will get on the desktop a csv file named from the current date-time.
    The values separator is set to match the Bento's requirements:
    If the decimal separator is period, the script uses commas.
    If the decimal separator is comma, the script uses semi-colons.
    This may be changed thru the setting of the property maybeSemiColon.
    According to the property needLF,
    embedded Returns will be replaced by LineFeeds
    or
    embedded LineFeeds will be replaced by Returns
    Yvan KOENIG (Vallauris, FRANCE)
    le 10 octobre 2008
    property needLF : true
    (* true = replace Returns by LineFeeds
    false = replace LineFeeds by Returns *)
    property maybeSemicolon : true
    (* true = use semiColons if decimal separator is comma
    false = always uses commas *)
    --=====
    try
    set |données| to the clipboard as text
    on error
    error "the clipboard doesn't contain text datas !"
    end try
    set line_feed to ASCII character 10
    if |données| contains tab then
    if maybeSemicolon then
    if character 2 of (0.5 as text) is "," then
    set |données| to my remplace(|données|, tab, quote & ";" & quote)
    else
    set |données| to my remplace(|données|, tab, quote & "," & quote)
    end if -- character 2 of (0.5…
    else
    set |données| to my remplace(|données|, tab, quote & "," & quote)
    end if -- maybeSemiColon
    end if -- |données| contains tab
    if needLF then
    if |données| contains return then set |données| to my remplace(|données|, return, line_feed)
    set |données| to my remplace(|données|, line_feed, quote & line_feed & quote)
    else
    if |données| contains line_feed then set |données| to my remplace(|données|, line_feed, return)
    |données| to my remplace(|données|, return, quote & return & quote)
    end if -- needLF
    set |données| to quote & |données| & quote
    set p2d to path to desktop as text
    set nom to my remplace(((current date) as text) & ".csv", ":", "-") (* unique name *)
    tell application "System Events" to make new file at end of folder p2d with properties {name:nom}
    write |données| to file (p2d & nom)
    --=====
    on remplace(t, tid1, tid2)
    local l
    set AppleScript's text item delimiters to tid1
    set l to text items of t
    set AppleScript's text item delimiters to tid2
    set t to l as text
    set AppleScript's text item delimiters to ""
    return t
    end remplace
    --=====
    --[/SCRIPT]
    Yvan KOENIG (from FRANCE vendredi 10 octobre 2008 13:47:36)

  • How do I  save a Numbers spreadsheet as an ASCII spreadsheet

    I need to convert an Appleworks spreadsheet to a Numbers spreadsheet and then save it as an ASCII file in order to upload it to my internet site.
    Conversion of the AW SS to Numbers is no problem. However, unlike AW, there is no selection I can make in the "Save As" menu to save the Numbers file as an ASCII.
    Any suggestions?

    Peggy:
    As you suggested, I copied and pasted my 450 row Numbers table into Pages (12 pages in total) and then converted it to text - I saved it to my desktop and renamed the file with a ".txt" tag. Then I uploaded to the server.
    The result when seen on the net is a page with 10 offices with total sales volume, units sold, etc. However, using the above procedure, while I do get the names of the 10 offices, I get no numbers.
    If any of you wish to contact my by email, I will direct you Peggy, Jerry and Brie, to the site to see the present result and future effort results.
    Thank you for your time and efforts.
    [email protected]

  • How do I save my numbers files as an xls for others to view with Mavericks

    After upgrading to OS Mavericks, I cannot save my files as an xls for others to view that have a pc. How do I do this for others to read?

    in Numbers, under the File menus select Export > Excel.

  • How do I save a numbers document as excel so it can be opened by windows?

    So i use my Mac Book Pro for some work documents, I use numbers and pages but since I updated to LION I cannot save any document as an excel it use to give me the option and now with auto save and versions it wont let me ive looked everywhere somebody please help me out!!!!

    You can still export it by going to the file menu and selecting "Export…" - you'll be presented with 3 options and one of them is Excel.
    Hope it helps.

  • How do I save a Numbers spreadsheet in .txt format?

    In order to import a contact list into an online program, I am supposed to Save As a TXT file (text delimited) - I am not given that option.  I have tried numerous ways to save as Excel and convert and cannot find anything that will work.  Please help.

    From my point of view, the easy clean way is to select the table
    copy
    Paste in Textedit
    set format to text
    Save.
    An alternate scheme is this old script :
    --{code}
    --[SCRIPTclipboard2textFile]
    Enregistrer le script en tant que Scriptl :clipboard2textFile.scpt
    déplacer le fichier créé dans le dossier
    <VolumeDeDémarrage>:Users:<votreCompte>:Library:Scripts:
    Copiez les données à exporter dans le Presse-papiers.
    menu Scripts > clipboard2textFile
    Le script créera un fichier texte.
    --=====
    L'aide du Finder explique:
    L'Utilitaire AppleScript permet d'activer le Menu des scripts :
    Ouvrez l'Utilitaire AppleScript situé dans le dossier Applications/AppleScript.
    Cochez la case "Afficher le menu des scripts dans la barre de menus".
    +++++++++
    Save the script as a Script, an Application or an Application Bundle:clipboard2textFile.xxx
    Move the newly created file into the folder:
    <startup Volume>:Users:<yourAccount>:Library:Scripts:
    Coopy the datas to export into the clipboard
    menu Scripts > clipboard2textFile
    The script will create a text file.
    --=====
    The Finder's Help explains:
    To make the Script menu appear:
    Open the AppleScript utility located in Applications/AppleScript.
    Select the "Show Script Menu in menu bar" checkbox.
    +++++++++
    Yvan KOENIG (Vallauris FRANCE)
    7 juillet 2009
    --=====
    on run
              try
                        set enTexte to the clipboard as text
                        set fName to (do shell script "date " & quote & "+_%Y%m%d-%H%M%S.txt" & quote)
                        set p2d to path to desktop
                        tell application "System Events" to make new file at end of p2d with properties {name:fName}
                        write enTexte to file ((p2d as text) & fName)
              on error
                        if my parleAnglais() then
                                  error "The clipboard doesn’t contain text data. Maybe you selected a Numbers sheet !"
                        else
                                  error "Le presse-papiers ne contient pas de données texte. Vous avez peut-être copié une feuille de Numbers !"
                        end if
              end try
    end run
    --=====
    on parleAnglais()
              local z
              try
                        tell application "Numbers" to set z to localized string "Cancel"
              on error
                        set z to "Cancel"
              end try
              return (z is not "Annuler")
    end parleAnglais
    --=====
    --[/SCRIPT]
    Yvan KOENIG (VALLAURIS, France) vendredi 7 octobre 2011 11:15:58
    iMac 21”5, i7, 2.8 GHz, 4 Gbytes, 1 Tbytes, mac OS X 10.6.8 and 10.7.0
    My iDisk is : <http://public.me.com/koenigyvan>
    Please : Search for questions similar to your own before submitting them to the community

  • How do I save a numbers spreadsheet on my iPad as a template?

    I have created a Spreadsheet on my iPad for staff to record time and materials on site an I would like to save it as a template so they can open a new copy of it each time and not change the original spreadsheet. Also I would like to be able to lock the cells on the spreadsheet so they can only enter data via the forms I have created. Can this be done in numbers on the iPad? Many thanks.

    Install the Number app on your iPad.

  • How to generate random numbers that doesnt contain characters?

    How do we generate random numbers in ESB ROuting Service/ XSL transformation that does not contain characters. I have been using "orcl:generate-guid()" , but it contains some characters, so, I substring it to get only numbers. I dont want to take this risk and in future, my substring itself may contain characters.
    Has anybdy tried this before?
    Thanks,

    If the goal is to have a pseudo random number then consider using the translate function to replace the occurances of the A - E characters with another digit. For example:
    translate(orcl:generate-guid(),'0123456789ABCDEF','0123456789123456')
    This will produce a 1 for A, 2 for B, etc. While not a valid hex to decimal conversion of the GUID value, it does get around the hex issue and might be sufficient for your purposes.
    I would perform a large sample test to see just how unique the values end up being.
    As for why hex is used, well GUID's are most commonly written in text as a sequence of hexadecimal digits such as: 3F2504E0-4F89-11D3-9A0C-0305E82C3301. i.e. 128 bits represented in 32 characters formatted into 5 sections.
    Hope this helps,
    Peter

  • 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?

  • Save a numbers spreadsheet as a simple text document?

    How do you save a numbers spreadsheet as a simple text document? I can't seem to find this option anywhere. Simply renaming the extension also seems to maintain rich text.

    An extension name is just a reminder helping us and the operating system to recognize which kind is the contents of a given file.
    Changing a trousers against a dress will not change Mr. Obama in Mrs. Clinton;-)
    Same thing for the files.
    At this time, Numbers doesn't offer the ability to export as a text file.
    Happily, our machines are delivered with TextEdit.
    Copy the block of cells of your choice to the clipboard
    Paste in an empty TextEdit document
    Format > Convert as text
    Save
    That's all folks.
    Of course, you may
    _Go to "Provide Numbers Feedback" in the "Numbers" menu_, describe what you wish.
    Then, cross your fingers, and wait _at least_ for iWork'09
    Yvan KOENIG (from FRANCE mardi 5 août 2008 18:07:34)

Maybe you are looking for

  • Open letter to Verizon regarding Tab 7.7 ICS Update

    Note: This is a copy of an e-mail I submitted to Verizon Wireless regarding my Galaxy Tab 7.7 LTE tablet, in order to ensure that Verizon receives the communication and to share the concern with the community which has substantially discussed the iss

  • Close Captions causes audio to be clipped

    I'm noticing that sometimes Captivate clips some of the audio as soon as you add closed captions to a series of slides?  If so, should I deal with that? To better illustrate my point, here are the steps to repeat: Configure three slides that are rela

  • SQL developer 1.5.4

    Hello, I am using sql developer 1.5.4. In the demo http://www.oracle.com/technology/obe/hol08/sqldev_migration/mssqlserver/viewlets/sqlserver_online.html?_template=/ocom/print On the new/select database creation, we can choose among oracle, access, m

  • Currency symbol in smartforms

    Hi All, How to place currencysymbole '£' (GBP) in the smartform before the Amount. This is very urgent.Please anybody help me. I will reward you points.

  • Trying to add mail

    I am trying to add my hotmail account to my iPad, but it's not possible to verificate it. I dont know what to do and where the problem is. Can anyone help me ? Thank you.