Random numbers in arrays

i have been faced with a new problem, i have to generate a random number (between 0-63) of random numbers (between 0-63).
Can i do this all in one array to randomly generate an array containing the random number of elementnts and set each of the elemnt to a random value.
Random x = new Random();
int j= x.nextInt(63);
String [j] numbers;
Random q = new Random();
for(j=0, j<=numbers.length, j++)
   int f= q.nextInt(63);
  numbers[j] =f;
} I had an idea of doing something like the code above can any see a better way to do it.

I am getting this error
java.lang.ArrayIndexOutOfBoundsException: 15
from
numbers[z] = rng.nextInt(63);i think this is because i am randomly calling the method, so it runs through it once but the second time it flags up the error.
void Randm()
                     Random rng = new java.security.SecureRandom();
                int o = rng.nextInt(63);//I hope you know this is zero to 63 exclusive, i.e., it can't return 63
                int [] numbers = new int[o];
                for(int z = 0 ; z <= numbers.length ; z++)
                    numbers[z] = rng.nextInt(63);// again, this will not return 63
                    System.out.println("ran gen "+numbers[z]);
}I think it may be the way i am declaring the array, can anyone shed some light on the situation.

Similar Messages

  • Need help with random numbers

    hi i need to generate 2 random numbers from array list . and then take out that two numbers from list.
         String[] plcard = { "AC", "KC", "QC", "JC",
              "10C", "9C", "8C", "7C","6C","5C","4C","3C","2C", "AD", "KD", "QD", "JD",
              "10D", "9D", "8D", "7D","6D","5D","4D","3D","2D", "AS", "KS", "QS", "JS",
              "10S", "9S", "8S", "7S","6S","5S","4S","3S","2S", "AH", "KH", "QH", "JH",
              "10H", "9H", "8H", "7H","6H","5H","4H","3H","2H",};
    this is the list if someone can help me i would appreciate
    thanks in advance

    haha, never noticed the .shuffle(List) method!
    maybe java is getting too convenient (just kidding)?
    i never wrote a card game.
    how would the more programmingly gifted of us do this?
    this is my shot at it for what its worth...
    public class Card{
    public Card(int rank, int suit){
    this.rank = rank;
    this.suit = suit;
    int rank (or String i suppose)
    int suit;
    static final club = 1;
    static final spade = 2;
    static final heart = 3;
    static final diamond = 4;
    public class Shuffler{
    public Shuffler(){
    int NumOfDecks = 1;
    Vector ShuffledDeck;
    // num of decks
    for(int i = 0; i < NumOfDecks){
    // 4 suits
    for(int j = 0; j < 4; j++){
    // 13 ranks
    for(int k = 0; k < 13; k++){
    ShuffledDeck.add(new Card(k, j));
    } // suits
    } // num of decks
    Collections.shuffle(ShuffledDeck);
    // Done?
    }

  • I am trying to generate an array of 30 random numbers. after every 5 readings a new vi should open and tell the user that 5 readings has been completed. and again carry on with the generation of array.

    since i do not have a transducer now, i am currently generating an array of 30 random numbers. after every 5 readings a warning should be given to the user that 5 readngs are complete. this cycle should repeat. the array size is 30.
    please help me out,  waiting for reply asap.
    once i have the transducer, i will be taking 30 analog samples and then after every 5 smaples that wraning will be displaye din a new VI
    Solved!
    Go to Solution.

    Use a while loop with a time delay representing your sampling period.
    Use the count terminal to check if equals 4, so 4th iteration=5th sample.
    Use a case structure. The true case will only be executed on the 4th iteration.
    In the true case place a subVI  with your desired message in the front panel. Go to the VI properties window and set "open front panel when called".
    The closing condition of the warnign is not giving in your description.
    Consider that rather than usign a subvi for this, you could use the "One/Two/Three button dialog" or "display message" vis at the "dialog and user interface" pallete.
    Please give it a try and send your own VI. Do not expect us to provide a working solution.
    Regards,

  • HELPwith array of random numbers!!!

    can anyone please write up a program that uses an array of random numbers from 0-100 and sort them out...
    if anyone can help me that would be great...i tried but i cannot figure it out...
    please just write the program so I just have to copy and paste :)

    This has to be the most asked question here, or at least it's way up there with classpath and path questions.
    Use the search feature to search the forum for random number generation and I swear you'll find more answers and code than you could possibly want.
    Good luck
    Lee

  • How to fill an array with random numbers

    Can anybody tell me how I can fill an array with thousand random numbers between 0 and 10000?

    import java.util.Random;
    class random
         static int[] bull(int size) {
              int[] numbers = new int[size];
              Random select = new Random();
              for(int i=0;i<numbers.length;i++) {
    harris:
    for(;;) {
    int trelos=select.nextInt(10000);
    numbers=trelos;
                        for(int j=0;j<i;j++) {
    if(trelos==numbers[j])
    continue harris;
    numbers[i]=trelos;
    break;
    return numbers;
    /*This method fills an array with numbers and there is no possibility two numbers to be the
         same*/
    /*The following method is a simpler method,but it is possible two numbers to be the same*/
    static int[] bull2(int size) {
         int[] numbers = new int[size];
    Random select = new Random();
    for(int i=0;i<numbers.length;i++)
              numbers[i]=select.nextInt(9);
              return numbers;
         public static void main(String[] args) {
    int[] nikos = random.bull(10);
    int[] nikos2 = random.bull2(10);
    for(int i=0;i<nikos.length;i++)
    System.out.println(nikos[i]);
    for(int i=0;i<nikos2.length;i++)
    System.out.println(nikos2[i]);

  • How do I generate an array of random numbers that relate to an output wave that falls within a certain frequency range?

    I have been creating random numbers that I'm using within a system, the system is working fine, but now I have realised that the random numbers must be outputted to speakers in such a way as to filter out all but a low frequency range.
    I was thinking about generating a dither signal with a bandpass filter, but could not get it to give me out a full array of 250 values which I could then manipulate.
    The sampling frequency of the output is 200Hz and the 250 data points must fall within the 0-100Hz range.
    Another course of action I am considering is to use an FFT and an inverse FFT to get the data that I'm looking for, but I'm fair
    ly inexperienced with using labVIEW and can't quite get it to work.
    Thanks for the help,
    Hank.

    As you may already know, in the Functions palette/Analysis VIs/Filters VIs are VIs for filtering. There are also some examples for using these filters under Examples/Analysis/fltrxmpl. You may find some of these are related to your situation, especially for filtering out the higher values.
    An option is to simply output the random values to a Comparison/"less than or equal" function, where only values <= to 100 would be sent to an array which is in a For loop. Use the iteration counter of the For loop to count up to 250, at which time you would pass the whole array to your next node. This would let you have 250 values between 0 and 100 for your final array.
    Good luck.

  • Array of unique random numbers - help?

    basically, i'm trying to create a BINGO card.
    i stared learning Java a week ago and am finding it easy to learn and use....at least so far.
    my instructor gave me the assignment to created a BINGO card. so i used the system.out.format command to make 5 tab fields, 8 spaces each ("%8s %8s %8s %8s %8s", "B", "I", "N", "G", "O"). although the assignment only wanted me to think numbers out of thin air, just to use as examples, i went above and beyond with the idea to make a BINGO card generator that could actually function.
    then i started the random number sequences, using the Math.random() command. all told, there are 24 of these in the program, one for each number on a bingo card. the field in the middle is the FREE space, so it has no Math.random command.
    in BINGO, each letter (one of my five tab fields) can have a number in ranges of 15. B is 1 to 15, I is 16 to 30, etc. it looks similar to this:
    B I N G O
    9 19 39 57 66
    3 28 32 51 74
    3 29 FREE 46 70
    14 28 43 55 67
    9 24 35 59 62
    as you can tell, i'm having trouble with actually making unique random numbers so that none repeat.
    is there a command or string or something to help me accomplish this?

    The best way I've come up with is to use an object to store the numbers that implements Collection--like ArrayList...
    Then you load it with the range of numbers that you want and call, shuffle() on the object, that will randomize your range of numbers and then you can choose the quantity you want from the storage object. So let's say you need 25 number in the range of 1 to 100:
    Add the numbers (you have to use classes so I would do Integers) 1 to 100;
    call shuffle()
    pull back the first 25 numbers
    This will guarantee that each number is distinct and in a random order.
    If you need multiple sheets populated, you can just call shuffle() between population of each sheet.
    package Junk;
    import java.util.ArrayList;
    import java.util.Collections;
    class Junk{
      private ArrayList<Integer> l;
      Junk(){
        l = new ArrayList<Integer>();
      public void loadList(int s, int e){
        for(int i=s; i<=e; i++){
          l.add(new Integer(i));
      public void randomizeList(){
        Collections.shuffle(l);
      public void printList5(){
        for(int i=0; i<5; i++){
          System.out.println(l.get(i));
      public static void main(String[] args){
        Junk j = new Junk();
        j.loadList(10,99);
        j.randomizeList();
        j.printList5();
        System.out.println();
        j.randomizeList();
        j.printList5();
    }

  • How can you generate Multiple random numbers from 1 to 49?

    I am very new at programming with the iPhone SDK and I need some help with a project I am working on. What I want to do is set up a window with 6 labels and 1 button. When the user clicks the button, the program will populate 6 randomized numbers each ranging from 1 to 49, and then place each of 6 numbers in a label. But each time the program ends and starts again the numbers cannot be the same, and also when the user clicks the button, no label can have the same number twice, so for example. If label 1 had the number 10, the other 5 labels cannot have that number until the button is clicked again. I know how to set up the interface, I just need the code. I would so greatly appreciate someone's help in this matter. I have been trying to do this for days and I cannot figure it out. Possibly someone who knows tons about Objective C programming can help me!
    Thank-you so very much!!

    I see that you're writing a lottery number generator. Perhaps the easiest way to do it is to emulate a real lottery: fill an array (NSMutableArray, probably) with the numbers between 1 and 49, pick one at random, remove that number from the array, and repeat. (You can think of the numbers as being the balls and the array as being the machine that pops them out.)
    One simple way to get the random indices needed is to extract six random bytes from Randomization Services using SecRandomCopyBytes, then loop over them, using the modulo operator (%) to select an index within the size of the array.
    And no, I'm not going to write your code for you. If I was going to do that, I could package and sell the app myself.

  • Random numbers without duplicates

    Hello,
    I'm having trouble locating an explained example for selecting a set of random numbers without duplicates. Specifically, I'm working on this example from Ivor Horton's Beginning Java, chapter 3.
    3. A lottery program requires that you select six different numbers from the integers 1-49. Write a program to do this for you and generate five sets of entries.
    This is not homework, I'm just trying to teach myself Java to eventually work my way up to servlets and JSPs.
    This is what I have so far. I tried to use array sorting but it didn't work (the first three numbers in my entries was always 0), so I commented out that part. I've included sample output after the code. I don't necessarily need the exact code although that would be nice; I just need at least an explanation of how to go about making sure that if a number has been picked for an entry, not to pick it again.
    Thanks for any help,
    javahombre
    package model;
    import java.util.Random;
    import java.lang.Math.*;
    import java.util.Arrays;
    public class Lottery {
    public static void main(String[] args) {
    // Lottery example.
    // We need the following data:
    // - An integer to store the lottery number range (in this case 59).
    // - A mechanism to choose a number randomly from the range.
    // - An array to store the entries (6 different numbers per entry).
    // - A loop to generate 5 sets of entries.
    int numberRange = 59;
    int currentPick = 0;
    int[] entry = new int[6]; // For storing entries.
    //int slot = -1; // For searching entry array.
    Random rn = new Random();
    for (int n = 0; n < 5; n++)
    // Generate entry.
    for (int i = 0; i < 6; i++)
    currentPick = 1 + Math.abs(rn.nextInt()) % numberRange;
    //Arrays.sort(entry);
    //slot = Arrays.binarySearch(entry, currentPick);
    //System.out.println("i: " + i + "\t| slot: " + slot + "\t| pick: " + currentPick + "\t| compare: " + (slot < 0));
    // Add the current pick if it is not already in the entry.
    //if (slot < 0)
    entry[i] = currentPick;
    System.out.println("pick entered: " + currentPick);
    // Output entry.
    System.out.print("Entry " + (n + 1) + ": ");
    for (int j = 0; j < 6; j++)
    System.out.print(entry[j] + "\t");
    System.out.println("");
    // Set the array contents back to 0 for next entry.
    Arrays.fill(entry,0);
    Sample output (notice duplicates, as in Entry 3):
    pick entered: 11
    pick entered: 29
    pick entered: 33
    pick entered: 8
    pick entered: 14
    pick entered: 54
    Entry 1: 11     29     33     8     14     54     
    pick entered: 51
    pick entered: 46
    pick entered: 25
    pick entered: 30
    pick entered: 44
    pick entered: 22
    Entry 2: 51     46     25     30     44     22     
    pick entered: 49
    pick entered: 39
    pick entered: 9
    pick entered: 6
    pick entered: 46
    pick entered: 46
    Entry 3: 49     39     9     6     46     46     
    pick entered: 23
    pick entered: 26
    pick entered: 2
    pick entered: 21
    pick entered: 51
    pick entered: 32
    Entry 4: 23     26     2     21     51     32     
    pick entered: 27
    pick entered: 48
    pick entered: 19
    pick entered: 10
    pick entered: 8
    pick entered: 18
    Entry 5: 27     48     19     10     8     18     

    NOTE: the array reference to [ i ] seems to be misinterpreted as italics by the posting form. I've reposted the message here, hopefully it will show the code properly.
    Thanks again,
    javahombre
    Hello,
    I'm having trouble locating an explained example for
    selecting a set of random numbers without duplicates.
    Specifically, I'm working on this example from Ivor
    Horton's Beginning Java, chapter 3.
    3. A lottery program requires that you select six
    different numbers from the integers 1-49. Write a
    program to do this for you and generate five sets of
    entries.
    This is not homework, I'm just trying to teach myself
    Java to eventually work my way up to servlets and
    JSPs.
    This is what I have so far. I tried to use array
    sorting but it didn't work (the first three numbers in
    my entries was always 0), so I commented out that
    part. I've included sample output after the code. I
    don't necessarily need the exact code although that
    would be nice; I just need at least an explanation of
    how to go about making sure that if a number has been
    picked for an entry, not to pick it again.
    Thanks for any help,
    javahombre
    package model;
    import java.util.Random;
    import java.lang.Math.*;
    import java.util.Arrays;
    public class Lottery {
    public static void main(String[] args) {
    // Lottery example.
    // We need the following data:
    // - An integer to store the lottery number range (in
    this case 59).
    // - A mechanism to choose a number randomly from the
    range.
    // - An array to store the entries (6 different
    numbers per entry).
    // - A loop to generate 5 sets of entries.
    int numberRange = 59;
    int currentPick = 0;
    int[] entry = new int[6]; // For storing entries.
    //int slot = -1; // For searching entry
    array.
    Random rn = new Random();
    for (int n = 0; n < 5; n++)
    // Generate entry.
    for (int i = 0; i < 6; i++)
    currentPick = 1 + Math.abs(rn.nextInt()) %
    numberRange;
    //Arrays.sort(entry);
    //slot = Arrays.binarySearch(entry, currentPick);
    //System.out.println("i: " + i + "\t| slot: " + slot +
    "\t| pick: " + currentPick + "\t| compare: " + (slot <
    0));
    // Add the current pick if it is not already in the
    entry.
    //if (slot < 0)
    entry[ i ] = currentPick;
    System.out.println("pick entered: " + currentPick);
    // Output entry.
    System.out.print("Entry " + (n + 1) + ": ");
    for (int j = 0; j < 6; j++)
    System.out.print(entry[j] + "\t");
    System.out.println("");
    // Set the array contents back to 0 for next entry.
    Arrays.fill(entry,0);
    Sample output (notice duplicates, as in Entry 3):
    pick entered: 11
    pick entered: 29
    pick entered: 33
    pick entered: 8
    pick entered: 14
    pick entered: 54
    Entry 1: 11     29     33     8     14     54
    pick entered: 51
    pick entered: 46
    pick entered: 25
    pick entered: 30
    pick entered: 44
    pick entered: 22
    Entry 2: 51     46     25     30     44     22
    pick entered: 49
    pick entered: 39
    pick entered: 9
    pick entered: 6
    pick entered: 46
    pick entered: 46
    Entry 3: 49     39     9     6     46     46
    pick entered: 23
    pick entered: 26
    pick entered: 2
    pick entered: 21
    pick entered: 51
    pick entered: 32
    Entry 4: 23     26     2     21     51     32
    pick entered: 27
    pick entered: 48
    pick entered: 19
    pick entered: 10
    pick entered: 8
    pick entered: 18
    Entry 5: 27     48     19     10     8     18

  • How do you generate multiple random numbers between 1 and 49

    I am new at mac programming and I want to make an iPhone app with the free SDK. What I would like to try is a random number generator. I imagine it as when the user clicks a button 6 random numbers from 1 to 49 would appear in a label or another control. If someone could please give me the code that would place these randomized numbers in a label I would greatly appreciate it. I know how to link all the controls together, I just need the code. Thank-you to anyone that can help!

    semi-sudo code goes here
    --prepare and array which will have number from 0 to 49
    --loop thru the array like this
    int i=0
    for (i; i<=49; i++) {
    int a=arc4random() % 49] ;
    int b=arc4random() % 49];
    --here exchange the objects so that they are shuffled
    [myArray exchangeObjectAtIndex:a withObjectAtIndex:b];

  • Random Numbers with Objective-C

    Hey Guys,
    I'm creating a blackjack program and I need to randomize 52 numbers, ensuring not to repeat any number.
    I know I can use the following to generate a number between 1-52, but I need the to eliminate the possibility of the same card being drawn twice:
    cardNumber = arc4random() % 52 + 1;
    Any idea on how I would do this? Code example would be helpful!
    Thanks,
    Justin

    Hi Justin -
    Justin Carman wrote:
    I'm creating a blackjack program and I need to randomize 52 numbers, ensuring not to repeat any number.
    I would initialize an array (the deck) with the card values, then use your random number as the index into the array. Each time a card is chosen just remove its value from the deck and decrement the modulus of the random numbers. NSMutableArray makes a nice deck for this purpose since its count is automatically decremented each time a value is removed. E.g.:
    // AppController.m
    #import "AppController.h"
    #define N_DECK 52
    @implementation AppController
    @synthesize cardArray; // @property (nonatomic, retain) NSMutableArray *cardArray;
    - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    self.cardArray = [NSMutableArray arrayWithCapacity:N_DECK];
    - (IBAction)newDeck:(id)sender {
    [cardArray removeAllObjects];
    for (int i = 0; i < N_DECK; i++) {
    [cardArray addObject:[NSNumber numberWithInt:i+1]];
    // NSLog(@"newDeck: cardArray=%@", cardArray);
    - (IBAction)getCard:(id)sender {
    // check the array
    int count = [cardArray count];
    assert(count <= N_DECK);
    if (count < 1) {
    NSLog(@"getCard: Empty deck");
    return;
    NSLog(@"getCard: count=%d", count);
    // select a card from the array
    int index = arc4random() % count;
    NSNumber *selected = [cardArray objectAtIndex:index];
    NSLog(@"getCard: index=%d selected=%@", index, selected);
    // print the value of the selected card
    int card = [selected intValue];
    NSLog(@"getCard: card=%d", card);
    // remove the selected card from the array
    [cardArray removeObjectAtIndex:index];
    // note selected NSNumber object has been released
    // NSLog(@"getCard: cardArray=%@", cardArray);
    @end
    For extra credit you might want to wrap the above in a custom Deck class.
    Hope that helps!
    - Ray

  • Random numbers

    I'm doing a java program using random numbers.
    I would like to avoid that each generated number, besides unique, is different from its index in array - for instance, the first number in array is not number 1, the second is not number 2, the third not number 3, and so one.
    Can someone help ?
    That�s my relevant code :
         boolean isRepeated = false;
            int [] rNums = new int [t1];
            for (int x = 0 ; x < t1 ; x++)
            do
            isRepeated = false;
           rNums [x] = (int) ((Math.random () * t1) + 1);
           for (int y = 0 ; y < x ; y++)
               if (rNums [x] == rNums [y])
           isRepeated = true;
           break;
           while (isRepeated);

    Any suggestion ?Not really.
    The not reapeating part by itself is easy. Either populate the array with numbers that match the indices and then shuffle, or just keep track of which numbers you've used to far and get the next number in a loop until you get one you haven't used up yet.
    The no-number-at-its index (and by the way, array indices start with 0, not 1) is fairly easy. Say your array is 10 elements, 0..9. So you generate a random number in the range 0..8 (9 possible values). Say we're trying to populate index 3. If the number generated is < 3, then use it as-is. If it's >= 3, then add 1.
    Putting them together is harder. And you could end up with a situation where 0-8 are populated, and the only number that's not used and the only index that's not used are both 9.
    Why are you imposing these restrictions?

  • 6 random numbers without repeat

    I'm trying to make a 6 digit random number generator between 1 and 48. When the user click a button 6 random numbers show up in 6 different textFeilds. The problem is that I don't want the same number twice. How can I generate 6 different random numbers without using return and breaking out of the function?
    import flash.events.Event;
    stop();
    btn.addEventListener (MouseEvent.CLICK, random1);
    function random1 (evt:Event) {
              display1.text = "";
              display2.text = "";
              display3.text = "";
              display4.text = "";
              display5.text = "";
              display6.text = "";
              var r1 = Math.floor(Math.random()*(1+48-1))+1;
              var r2 = Math.floor(Math.random()*(1+48-1))+1;
              var r3 = Math.floor(Math.random()*(1+48-1))+1;
              var r4 = Math.floor(Math.random()*(1+48-1))+1;
              var r5 = Math.floor(Math.random()*(1+48-1))+1;
              var r6 = Math.floor(Math.random()*(1+48-1))+1;
              if (r2 == r1 || r3 == r2 || r4 == r3 || r5 == r4 || r6 == r5) {
                        return;
              var liste:Array = new Array();
              liste.push(r1,r2,r3,r4,r5,r6);
              liste.sort(Array.NUMERIC);
              display1.text = String(liste[0]);
              display2.text = String(liste[1]);
              display3.text = String(liste[2]);
              display4.text = String(liste[3]);
              display5.text = String(liste[4]);
              display6.text = String(liste[5]);

    Here's the code for the approach mentioned with your textfields included
    btn.addEventListener (MouseEvent.CLICK, random1);
    function random1 (evt:Event) {
        var nums:Array = new Array();
        // fill the array of numbers
        for(var i:uint=1; i<=48; i++){
            nums.push(i);
        shuffle(nums);
        // grab the first six in the shuffled array
        var liste:Array = nums.splice(0,6);
        // assign the values to the textfields
        for(var j:uint=1; j<=6; j++){
            this["display"+String(j)].text = String(liste[j]);
    function shuffle(a:Array) {
        var p:int;
        var t:*;
        var ivar:int;
        for (ivar = a.length-1; ivar>=0; ivar--) {
            p=Math.floor((ivar+1)*Math.random());
            t = a[ivar];
            a[ivar] = a[p];
            a[p] = t;

  • How to genrate non-repeating random numbers

    Hi everyone, i'm trying to write a for loop that genrate a
    list of non-repeating random index number for an array list but i
    can't seem to get the random numbers non-repeat. I'm a newbie in
    Flex 2 so it would be great if anyone could show me what seems to
    be the problem in this code:
    Thank you very much.
    Richie
    for (var j:Number = 0; j < tempArray.length; j++)
    var randomNum:Number =
    Math.round(Math.random()*tempArray.length);
    if (j - 1 >= 0)
    while (randomNum == randomIndex[j-1].index)
    randomNum = Math.round(Math.random()*tempArray.length);
    //Push the random number in an array
    randomIndex.push({index: randomNum});
    Alert.show(randomNum.toString());
    }

    Dont' worry about it guys, i already got it thanks!

  • Figuring out the occurence of random numbers?

    So, I'm taking this Computer Science class, and I've been struggling so much with today's lesson.
    For this particular question, I have to get 20 random numbers between 1-5, represent them in text format, and the show how often each of the numbers occured. I've done the first two of the three parts, but this last part really has me stumped..
    (Note: I'm using Ready to Program by Holt.... so I'm using their console)
    Here's the code I got so far:
    import java.util.*;
    import hsa.Console;
    import java.io.*;
    public class RandomNumbers
        static Console c;
        static public void main (String[] args) throws IOException
            c = new Console ();
            int a;
            Random generator = new Random();
            c.println("Generating Numbers: ");
            for(a=1;a<=20;a++)
                int r = generator.nextInt(5)+1;
                    switch(r)
                         case 1: c.print("One",10); break;
                         case 2: c.print("Two",10); break;
                         case 3: c.print("Three",10); break;
                         case 4: c.print("Four",10); break;
                         case 5: c.print("Five",10); break;
    }}

    I had a similar assignment my last semester for C++. I would think the general idea is the same.
    Here I declare an Array. Then I store the values of the dice rolled in the array and display it on the screen. The syntax will be different since you are not using C++.
    #include <iostream>          // preprocessor directive
    #include <ctime>          // preprocessor directive
    #include <cmath>          // preprocessor directive
    #include <cstdlib>          // preprocessor directive
    using namespace std;     // enables preprocessor directives
    int random_int(int a, int b);          // function prototpye
    int main ()     // main function
         srand(time(NULL));          // enables random numbers to be generated
         int d1, d2, sum;                         // declaring variables
         int a[10] = {0,0,0,0,0,0,0,0,0,0};     // initializes valus in array to 0
         int roll;                                   // declaring variable
         cout << "Roll how many times?";          // ask number of times to roll dice
         cin >> roll;                              // get number of times to roll dice
         for(int i=0; i<=roll; i++)               // to roll the dice the numbers or times asked
              d1 = random_int(1,6);               // generates number for die 1
              d2 = random_int(1,6);               // generates number for die 2
              sum = d1 + d2;                         // adds the two dice together     
              if(sum == 2)                         // increase value in array  by 1 that corresponds to 2
                   a[0]++;
              else if(sum==3)                         // increase value in array  by 1 that corresponds to 3
                   a[1]++;
              else if(sum==4)                         // increase value in array  by 1 that corresponds to 4
                   a[2]++;
              else if(sum==5)                         // increase value in array  by 1 that corresponds to 5
                   a[3]++;     
              else if(sum==6)                         // increase value in array  by 1 that corresponds to 6
                   a[4]++;
              else if(sum==7)                         // increase value in array  by 1 that corresponds to 7
                   a[5]++;
              else if(sum==8)                         // increase value in array  by 1 that corresponds to 8
                   a[6]++;
              else if(sum==9)                         // increase value in array  by 1 that corresponds to 9
                   a[7]++;
              else if(sum==10)                    // increase value in array  by 1 that corresponds to 10
                   a[8]++;          
              else if(sum==11)                    // increase value in array  by 1 that corresponds to 11
                   a[9]++;
              else if(sum==12)                    // increase value in array  by 1 that corresponds to 12
                   a[10]++;
         for(int j = 2; j<=12; j++)                    
              cout << j << "  " << a[j-2] <<endl;          // output the array
         return 0; //exit program
    int random_int(int a, int b)          // used to generate te random numbers
         int random = rand()%(b-a+1) + a;
         return (random);
    }          

Maybe you are looking for

  • Bank Book

    Dear Experts, Please advise the report to view Bank Book day wise. Eg. Opening Balance, transactions, Closing Balance. Regards Adi

  • Active dataguard for Oracle 10g SE

    Hi all, I am having Oracle 10g SE and i need to ship the logs to the standby can i use active dataguard for this. Regards, Bobs

  • Bruning CDs where the files are in specific places and there are images

    I have bought a few CDs for OS x from the store and I notice that some of them having images in the background and the files are in a certain location within the window and there is even text. I am sure this is not possible with Tiger alone though I

  • To freez PO Doc date  In ME21n

    Hi expert , My Requirement is , i want to freez PO Doc date in Tcode ME21n Only show current date  while creating a new PO . Means no one could make the PO in previous or future date from current date . Date should come just like sy-date but not in c

  • MPS..........

    Hi friends, Can some one please tell me the concept and which scenerios we have to use Master Production Scheduling (MPS)? Some one told me that we are using MPS for component marked as "A part". What is this A-part in MPS? Actually I discussed lot w