Generating random questions without duplication

I have 10 questions in my java program,
I can get them randomly generated but how can I do without duplication ?
Any help much appreciated

My approach would be, when you first generate the questions put them in a List. Then use java.util.Collections.shuffle(List) to randomize the List.
http://java.sun.com/j2se/1.5.0/docs/api/java/util/Collections.html#shuffle(java.util.List)
http://java.sun.com/j2se/1.5.0/docs/api/java/util/List.html

Similar Messages

  • Random Test questions without duplication

    Hi ,
    I have 10 questions in my java program,
    I can get them randomly generated but how can I do without duplication ?
    Any help much appreciated

    Im just trying to shufle this list , when I print it , it gives always gives the same order , I tought shuffle would do it randomly, any help please ?
    import java.util.*;
    public class SetExample {
    public static void main(String args[]) {
    List list = new ArrayList();
    list.add("Bernadine");
    list.add("Elizabeth");
    list.add("Gene");
    list.add("Elizabeth");
    list.add("Clara");
         shuffle(list);
    public static void shuffle(List list)
         System.out.println(list);
    }

  • Generating Random questions

    Hi
    I am trying to get random questions which are stored in the database. I used the following code but questions are not unique.
    public void loadQuestion(){
    int len = qs.size();
    Random r = new Random();
    int[] rint = new int[6];
    for (int i =0;i!=6;i++){
    rint[i] =r.nextInt(len);               
    }

    public void loadQuestion(){
    int len = qs.size();
    System.out.println("Length: " + len);
    Random r = new Random();
    int[] rint = new int[6];
    for (int i =0;i < 6;i++){
    rint[i ] =r.nextInt(len);     
    System.out.println("Number: " + rint[ i ]);     
    }NOTE: when posting here you have to put a space in [ i ], otherwise
    the forum software thinks its an italics tag.
    Dont get clever with constructs like i != 6 its i < 6
    Use lots of verbose debugging lines like the 2 i added.
    Post the results you get.

  • How to make Random questions work without closing and restarting?

    I have a quiz using random question slides and random pools.
    The random slides display random questions when I run the CP4 file, let it close then relaunch it. I'm using an LMS.
    I would like to be able to repeat the quiz again without closing and relaunching, but my method does not work.
    I tried using a button (retake) on the last slide to 'jump to' slide 1 when clicked. The quiz does repeat, but show the exact same questions.
    I thought there might be a variable that would reset the quiz, but could not find one.
    Does anyone have method to do this?
    Thanks,
    Dave

    I don't know of a way. My experience is the same as yours. The quiz questions are selected and shuffled when the lesson is launched. When 'retake' is clicked, the quiz repearts the same questions. The only way to get a new set of questions is to close and relaunch it.
    I suppose there's be some function to invoke or array to manipulate via AS, but I've no idea what that may be...
    So no help here, just backing what you're seeing.
    Erik

  • 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

  • Some random questions about integration features

    Greetings,
    after working for a few weeks with Autovue's ISDK (web server) and having some sucess with its integration with our custom CMS, I have a few random questions about what can be done and what can't be done. So, instead of opening many new threads, I'll post them here together.
    1) Translation. We are localised in Russia, and its translation is incomplete. I have found a tra_en.properties file in AutoVue/bin, and a description about how to create a properties file for custom actions. But no information about how to translate to other languages - and russian translation appears to be packed within the jar of the applet. Is there a clean way to translate, or refine the current translation, so we don't get a mix of russian and english commands in the applet? Because my tries using EXTRABUNDLES have failed, as I don't want to add a bundle for extra actions, but to replace it for existing ones.
    2) Attachments in markups. Markups allow to attach other files, but since our CMS is custom, we only get the option to attach files from our local drives. We did no browse integration with the CMS, as people with different levels of permission will have different access to files there, and we considered unnecessary to provide that level of integration. We are considering to remove this action from the GUI, but before that I'd like to evaluate how hard would it be to generate an upload file action, so the attached file would be stored in the custom CMS and linked to it so the whole thing worked. My guess is "it will be hard and time consuming", so for now, we are considering to delete this feature in our integration.
    3) Is there a way to resize the Open markup dialog? We have several properties displayed, and fit well within a standard screen, but the dialog is small and you have to scroll the table to see all properties.
    Thanks for any assistance with these issues

    As always, thanks for the fast answer, Artash.
    Yes, now I see attachments are stored inside the markup file. The problem is, when I open markup mode for the attachment, since the attachment uses some kind of default access method, my url's from the integration with the background CMS are broken completely. I believe the ideal state here would be to make some kind of inner markup for the attachment, maybe stored within the original markup file along the attached file. Or maybe it works that way, and I need to access it with the default gui action instead of my custom one. If that is the case, is there any way to tell the gui file how to differentiate a standard opened file from an attached one? If so, the issue has solution. If not... Well, then maybe something escapes me.
    Edited by: Jordi Bosch on Apr 6, 2012 12:27 AM

  • 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

  • Convert to Question Pool random questions?

    We are updating a course we developed last year (prior to
    Captivate 3). This year we want to apply Captivate 3's "Question
    Pool random questions" to this course. Is there a way to create the
    question pool(s) in this existing quiz, and then add last year's
    questions to them without having to re-enter each question into the
    Question Pool Manager?
    Thank you for any tips!

    Hi Jan
    Sure thing. Just convert the version 1 or 2 project to a
    version 3 project. Then define a Question Pool. Once you have done
    that, switch to Storyboard view. Select the question slides you
    wish to add to the pool and right-click. You should be presented
    with an option to add the selected slides to the pool.
    Once you have moved the question slides to a pool, you would
    then insert Random slides that point to the pool.
    Cheers... Rick

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

  • Generate Key Events without pressing key???

    Hi,
    Is it possible to generate key events without pressing a key in swing???
    i dont know if the question is logical or not, but just i want to generate some display as if the key is pressed by the user
    Ashish

    assuming c represents a text field.
    This will type the character 'a' in the text field:
    c.dispatchEvent( new KeyEvent (c, KeyEvent.KEY_TYPED, 0, 0, KeyEvent.VK_UNDEFINED, 'a') );
    This will invoke Ctrl+F1, which will show the tool tip for the text field:
    c.dispatchEvent( new KeyEvent (c, KeyEvent.KEY_PRESSED, 0, KeyEvent.CTRL_MASK, KeyEvent.VK_F1) );

  • Certificate Widget and Random Question Slides

    I am in the process of evaluating Captivate 4. Twice now I have had an issue with using the random question slides with the certificate widget. In both cases I converted a Captivate 3 course in which the random question slides and corollary question pools had worked as they should. In both, I successfully added the certificate widget to the new course (Captivate 4) following the instructions in help.
    In the first course, only one question pool would work. The others simply showed up as a blank slide. I was able to fix that by merging all the questions into the one working question pool. Wasn't the way I had wanted to randomize the questions, but it allowed me to publish the course. The certificate widget did work.
    In the second course, none of the questions pools are working and the published version of the course skips right past the random questions that had been interspersed after each topic area. One again, this course had worked just fine in Captivate 3 and with Captivate 4, without the certificate widget. I do not wish to combine all the questions into one question pool. As I noted, I published the course without the widget and the questions worked just fine.
    This leads me to believe that I am doing (or not doing) something when I include the widget that is causing the problem. I can't imagine what that would be, but the fact that no one else seems to have posted this issue makes me think it is something I'm doing.
    I am not using an LMS. I'm publishing to .html file that resides on our LAN.
    I hope someone can help!
    Thanks!
    Susan

    Hi Peter,
    A number of users (myself included) have encountered issues with the random question slide feature - some of which is due to browser cacheing. If you can spare the time please use the web address I have included below to report this issue to the Adobe Captivate team.
    Adobe Captivate Feature Request/Bug Report Form 
    Best - Mark
    Visit the macrofireball blog

  • [captivate 3] random question slide doesn't work

    hello,
    I'm noob in Captivate.
    I use Captivate demo (in french).
    I want to make a quizz for my students.
    So, I create a "question pool manager" with 1 pool project
    "reseau_locaux".
    This pool project have 13 questions.
    Then I click "slides" on the filmstrip, I add a "Random
    question slide" and I click on the "Question pool menu" to select
    my pool project "reseau_locaux"
    After generating project, I have only 1 question from my
    question pool project.
    I read the help guide but it's not help me.
    It gets me crazy...
    I hope you understand my english.
    thanks

    Welcome to our community, Anthony
    Basically you are doing everything right. I'm a bit unclear
    on what you were expecting to see. Perhaps it will help you if I
    explain how the Question Pools and Random Questions work.
    You define a pool of questions using the Question Pools
    Manager. You advise you have done that. So far so good.
    You then insert a Random Question Slide. When you insert one
    of these, you point the slide at a Question Pool. You advise that
    you have done that too.
    I'm guessing here that perhaps you expected that by inserting
    a single Random Question Slide you would end up presenting all 13
    questions from the pool. Just in random order?
    If so, that's not how it was designed to work. What happens
    is that a single random question from the pool is presented. If you
    desire to see all 13 of your questions, but in random order, you
    need to insert 13 Random Question Slides and point them at your
    Question Pool.
    You may wonder at this point if you do this, will it would be
    possible to see perhaps question 2 multiple times. And the answer
    to that is no. Once a question has been presented, it is removed
    from consideration in the pool. So after the first one is
    presented, Captivate randomizes from what remains in the pool.
    Hopefully that helps better explain it.
    Cheers... Rick

  • Need An Algorithm That Generates Random Numbers

    Hi, I understand that there is a built-in random number generator. But, I need an algorithm that generator random numbers. Is there one available? Thanks.

    Hi, is the "Seminumerical Algorithms" a book?What
    the numbers 3141592621 and 907633385 stand for?The first is PI without a decimal... the second I
    don't know, it may as well be randomly picked.As far as I know the numbers aren't randomly picked. You want the distribution to be good, and the length of the serie should also be long. Some numbers causes the cycle to be short, or the distribution to be bad. I think there are articles that lists 'good' numbers.
    /Kaj

  • Re-Randomizing questions when resume data is on?

    Hi there,
    I suspect I might know the answer I get for this but its worth an ask anyway.
    Is there a way of re-randomizing questions when taking a course with resume data on?
    I've been getting into the nitty gritty of captivate with the functions it sends and I have found the ones for randomizing the questions but I can't run them without knowing the correct parameters (all the variables have confusing names such as gqs, pqs and so on)
    I talked to Adobe support in regards this and was told that  custom scripts were not supported and I would have to pay extra for a Dev support contract if I wanted a (I assume) software developers take on things which I think is a bit unfair considering having randomized questions really should be a basic feature of a course authoring software.
    I was also looking at having resume data turned off in captivate and sending out my own which would track the viewed section variables along with the current page and then having a script for captivate jump to the required page once the course was opened.
    Anyone have any experience with using your own resume data or any other ideas?
    Cheers

    Ok: This is what I understood: You do not want to Display a whole column of 0's (for Feb) but you want the user to be aware that there were 0 deliveries for feb.
    So if you run the report for a Calmonth Range of 01.2006 to 06.2006, then just after the Free Chars in the report, you should see a row like Cal/Year Month Jan 2006..June 2006. This shows that the report was run for Jan to June range and the results show months Jan, March, April, May, June implying that there is no data for Feb.

  • Run xlf + xls to generate ppt / swf - without opening Xcelsius

    Hello,
    I found you great community and I just signed
    because I need your help
    and I look forward to your ideas!
    My goal is a static data situation.
    I have a once designed dashboard, meaning one xlf.
    Now I want to run the xlf with an alway new analysis.xls.
    Of cause the the pattern of the analysis.xls is the same (only latest data).
    Now my question, how can I generate ppt files without opening Xcelsius.
    like:
    cmd:  run xlf on xls
    output: ppt or swf
    I really look forward to your messages and ideas!!!
    Thanks.
    Ivette

    Ivette, Any ideas to resolve your problem?

Maybe you are looking for