Get random items, no repetitive table

Hello!

I'm doing a 20-question, multiple-choice quiz. Each question is chosen at random in a table, and whenever the user clicks on the right answer, another random question comes up. I was not able to find a way to make sure not to repeat issues already selected. I tried to push the selected items in a table, then using $.grep and an if statement to check if the other randomly chosen question is already in the new table or not, but I couldn't get that to work.

My code in the Panel of compositionReady is:

var arr is ["Symbol_1", 'Symbol_2', 'Symbol_3', 'Symbol_4', 'Symbol_5', 'Symbol_6', 'Symbol_7', 'Symbol_8', 'Symbol_9', 'Symbol_10', 'Symbol_11', 'Symbol_12', 'Symbol_13', 'Symbol_14', 'Symbol_15', 'Symbol_16', 'Symbol_17', 'Symbol_18', 'Symbol_19', 'Symbol_20'];.

sym.setVariable ("arr", arr);

arr.sort (Function () {return 0.5 - Math.random ()});

arr. Length = 20;

var c = Math.floor (Math.random () * 100) %arr.length;

for (i = 0; i < 20; i ++) {}

SYM.$(arr[i]). Hide();

SYM.$(arr[ques]). Show();

};

and whenever you click on the right answer, I run this:

sym.getComposition () .getStage ().$("try_again1").hide ();

sym.getComposition () .getStage ().$("correct1").show ();

sym.getComposition () .getStage ().getSymbol("correct1").play ();

var arr = sym.getComposition () .getStage () .getVariable ("arr");

var c = Math.floor (Math.random () * 100) %arr.length;

for (i = 0; i < = 20; i ++) {}

sym.getComposition () .getStage ().$(arr[i]).hide ();

sym.getComposition () .getStage ().$(arr[ques]).show ();

}

An overview of this would be much appreciated!


Hi, bettiesac212-

Well, I took a quick glance to your project (including project files was very useful, which is said by the way).  So what happens, is that you have included my code snippet in the middle of all the other things happening in your file.  There are a lot of questions I had looking at your code, like:

  • What is 'e '?  Where did this come from?
  • Why did you an array.sort initially?
  • Why do you attribute arr.length?  It is a property of arr already, so there is no reason to assign this

Anyway, I cleaned up the code a bit to my snippet in.  I left some of her "as an exercise to the student", to paraphrase some of my old books, but I hope the console log will show you that usedArr is now a random picture that you can save.  If you save a variable that has the index, (aka "what question am I on?"), then you can get where you are now, add one, save this variable and are looking for the next item in usedArr and know that it is properly randomized.

For those who are looking for an answer, this is the code I ended up using:

var usedArr = new Array();

var currentIndex = 0;

While (currentIndex< 20)="">

var randNum is Math.floor ((Math.random () * 100)) % 20;.

If (usedArr [randNum] == undefined) {}

We can place an object!

usedArr [randNum] = arr [currentIndex];

currentIndex ++;

}

by do not increment the currentIndex, we force basically he draw again

}

for (i = 0; i< usedarr.length;="" i++)="">

Console.log ("index usedArr" + i + ":" + usedArr [i]);

}

You can save your new table and just browse each time

you say "next question."

I think that's more or less what I posted in my previous answer.  Bettie, I'll send you a link to your project files via private message in a few minutes.

Thank you

-Elaine

Tags: Edge Animate

Similar Questions

  • AS3 getting a random multiple number of table

    Hello:

    I have a hard time finding ways to manage the division with random numbers of tables using AS3.

    On my stage, I have two dynamic boxes; Box1 and box2 and a button, btn.

    in the Assembly, I have the following berries:

    var myDivisor:Array = [3,6,9,12,15,18,21,24,27,30];

    var myDivider:Array = [1,3,6];

    The idea is to divide 1 box per box of 2, so myDivisor should be a random number greater than a random number between myDivider

    WITH THE HELP OF BTN, HOW CAN I GET A RANDOM OF EACH TABLE, SO THIS DIVISOR NUMBER IS HIGHER THAN THE DIVISOR?

    In the timeline for button, here is the code:

    btn.addEventListerner (MouseEvent, CLICK, rNum);

    function rNum (MouseEvent): void

    {

    Box1. Math.Floor (Math.random) * myDivisor.length) / box2. Math.Floor (Math.random) * myDivider.leng th);

    }

    Please suggest ways to make this work.

    German

    var myDivisor:Array = new Array (3,6,9,12,15,18,21,24,27,30,23,89,90,1,34,56,78,99,345,456);
    var myDivider:Array = new Array (1,3,6);
    var divisor: int;
    var divisor: int;

    getNumbers();
    function getNumbers() {}
    divisor = getRandom (myDivisor);
    divisor = getRandom (myDivider);
    checkValues();
    }
    function getRandom(array:Array):int {}

    var NombrAl = Math.floor (Math.random () * array.length);
    return table [NombrAl];

    }
    function checkValues() {}
    If (getRandom (myDivisor) > getRandom (myDivider)) {}
    trace (getRandom (myDivisor));
    trace (getRandom (myDivider));

    } else {}
    getNumbers();
    }
    }

  • Returns the unique items in a table

    I would like to know how to get combanations of any table without repetitions of the same elements in a different order.

    The table is made of properties of the object and could have a variable number of elements.

    In other words, if I have an array of 2 elements for example

    [a, b]

    I want to receive 3 new arrays of void

    (1) [a]

    (2) [b]

    (3) [a, b]

    I don't want to receive [b, a] as having the same elements as [a, b] only in a different order.

    Well, if there just 2 items in the table then it's pretty easy, but when there is more then I do not understand!

    An array of 4 elements for example

    [a, b, c and d]

    would need to produce a new table of the following tables 15 sub

    (1) [a]

    (2) [b]

    (3) [c]

    (4) [d]

    (5) [a, b]

    (6) [a, c]

    (7) [a, d]

    (8) [b, c]

    (9) [b, d]

    (10) [c, d]

    (11) [a, b, c]

    (12) [a, b, d]

    (13) [a, c and d]

    (14) [b, c and d]

    (15) [a, b, c and d]

    A table of 5 elements would give me overtime 24 tables and so forth.

    I tried many ways with diddlysquat results

    Slice, splice and all things nice!

    If someone of you could share this trade secret with me, I would appreciate it a lot.

    Trevor

    Nice challenge!

    We could try this:

    function arrayParts(/*arr*/a, r,i,j,t,s,p)
    // -------------------------------------
    // Note: a is supposed to contain unique items
    // [if necessary, apply a makeUnique routine first]
    {
        if(! (i = Math.pow(2,a.length)-1) ){ return null; }
        (r=[]).toString = function(){return this.join('\r');};
    
        while(i--)
            {
            r[i] = t = [];
            s = (1+i).toString(2);
            p = (j=s.length) - 1;
            while( j-- ) '1'==s[j] && t[t.length]=a[p-j];
            }
    
        // Reorder by length [if needed!]
        // ---
        r.sort( function(x,y){return x.length-y.length;} );
    
        return  r;
    }
    
    // Sample code
    // ---
    var arrTest = ['Blue','Red','Yellow','Green','Black'];
    alert( arrayParts(arrTest) );
    

    Really not optimized, but it was pretty fun to write ;-)

    @+

    Marc

  • How can I determine which item in a table was just clicked on?

    I have a table set in place on my front. When user right click on an item in this table, I would like to be able choose among 3 different options. I have the shortcut menu works, but I need to know what element of the array of the user in a click with the right button to determine what values to change. How can I get the index of the item?

    Thanks for any help!

    https://decibel.NI.com/content/docs/doc-6406

  • How to write a simple select query to get the data of the table as an XML.

    How to write a simple select query to get the data of the table as an XML. In the query, I'm just adding items below which i need be there in the XML document
    select '<test_tag>'||EMP_NAME||'</test_tag>','<date>'||sysdate||'</date>' 
    from temp_table where id_num BETWEEN 1 AND 10;
    I have need to add the root tag as well in the beginning and the end of < root > < / root > this xml file. Please advice if this is possible with the select query
    without using XMLGEN, XMLQUERY or any other packages built and function?

    I need to URL escapes with the UTF-8 code points that we have already achieved using the utl_http package. Please help how to do that without using the utl_http package.

    What is wrong with him?

    At present, the only way I can think of to avoid a call to UTL_HTTP. SET_BODY_CHARSET is to write your own little wrapper.
    In this way, you can specify the Boolean parameter or omit it if you choose to use named parameters:

    SQL> create or replace function my_url_escape (url in varchar2)
      2  return varchar2
      3  deterministic
      4  is
      5  begin
      6   return utl_url.escape(url, false, 'AL32UTF8');
      7  end;
      8  /
    
    Function created
    
    SQL> select my_url_escape('http://some.uri.com/param?lang=fr&text=contrôle') from dual;
    
    MY_URL_ESCAPE('HTTP://SOME.URI
    --------------------------------------------------------------------------------
    http://some.uri.com/param?lang=fr&text=contr%C3%B4le
     
    
  • They needed to seek random rownum in a table

    Hi all

    I need to go get two records random table, every time I question him. for example my_emp_table if it contains the unique employee ID, is possible to write a query that would give a two records of employees at random, say for the first record of employee of 11 and 18 and next run 20 and 28.

    We can get random values by select TRUNC (dbms_random.value (1,250)), TRUNC (dbms_random.value (1,250)) twice num
    But how to use these values to get the nth record using sql?

    Any help will be appreciated.

    Thank you very much!!
    -Shashank

    See my solution for that!

    select *
    from ( select *
              from tab1
                   , tab2
                   , tab3
                   , tab4
               where .....
               ORDER BY dbms_random.value
            )
    where rownum <= 2
    

    Published by: ascheffer on February 18, 2011 15:33

  • Problem to display items in a table

    I have a list of delimited by commas, called "listtest.

    I put each item in the list in a table called 'params '.
    Now I use a loop 'for' for each element of the array.
    I tried the code below, but I don't get the items.

    See code below:

    var params: Array = listtest.split(",");

    for (var i: int = 0; i < params.length; i ++) {}
    Alert.Show (new String (params, ));
    Alert.Show (new String(params
    .displayName));
    }

    Can someone tell me how to get the items in the Alertbox.

    THX

    I had myself. I fink I slept all by writing code.

    It's so simple!

    Here it is:

    for (var i: int = 0; i)< params.length;="">
    Alert.Show (new String (params, ));
    }

    Rgds,
    Yaya

  • Error code: How can I get an item in the Recycle Bin?

    I can't put a webarchive into the trash.  Error message says, "the operation cannot be completed because one or more required elements was not found (error code - 43) how can I get the item in the Recycle Bin?

    reset

    then try again.

  • getting random symbols when I type on macbook pro

    I get get random symbols (usually [inserted randomly between text) when I tap on Macbook Pro running OS X El Capitan.

    That usually happens when you press the P button, which is located just next door?

    Maybe try system preferences and make sure that your "Keyboard" and "language and region" settings are correct.

  • get a row in a table 2D-TestStand

    What is the syntax to get a row in a table 2D-TestStand

    NEITHER told I have to recursively or outside.

    Here is my approach to get a rank of recursively in TS.

    PreExpression:

    Parameters.Row = {}, Locals.i = 0, / / initialize variable

    GetArrayBounds (Parameters.Array2D, Locals.loBounds, Locals.hiBounds),

    Locals.columnQty = 1 + Val (Mid (Locals.hiBounds, Find (Locals.hiBounds, "]") + 2, Len (Locals.hiBounds) - 3 - Find (Locals.hiBounds, "]")));

    Locals.WhileExpr = Locals.i «»< locals.columnqty",="" set="" condition="">

    Locals.DoExpr = "Parameters.row += {Parameters.Array2D [Parameters.rowIndex] [Locals.i]} ++ Locals.i" / / defines the expression to run recursively

    The Expression:

    Evaluate (locals. RcrExpr)

    where Locals.RcrExpr is:

    Evaluate (locals. WhileExpr)? (Evaluate (Locals.DoExpr), Evaluate (Locals.RcrExpr)):

  • How can I read items in four tables and store them in variables?

    Greetings,

    I have 4 tables which I read to control an autonomous robot vehicle as instructions.

    I must be able to read the first elements of each table and store in separate variables 4 (direction, speed, angle, distance). Wait until the first statement has been executed. Then I move on to the second elements of each array. I'll repeat this until I went through all the elements. I am struggling to figure out how to do this?

    Please note:

    -The number of items in the tables is always the same, although the number of items varies as can be less instructions or more.

    For example, a full trial takes 1st element of table 1, table 2, table 3 and table 4 and it builds something like: forward, 10, 20, to the left. This will then be the robot moving forward at a speed of 10 over a distance of 20 and then turn left. Once this done then it contains the elements 2 and so on.

    Please find attached my VI that reads a text file and creates 4 berries.

    Thank you.

    stanm13 wrote: Unfortunately, I don't think you understood my question.

    Then, I would say a) you don't understand the answer or b) you explain well enough.

    To make each element of an array, using a loop FOR with autoindexing entered is the way to go.

  • How Split items in a table

    Hi guys

    I have signal consisting of a few numbers... .they are declared separately to Labview as x, y, z.

    So I need a way to group 3 these items in a table (for example) as x refes to a data point, number there is tension and z is the current.

    I would then separate the 'picture' in a XY Chart for I draw vs V.

    Any suggestions?

    Rgards

    B

    Hi Barrys,

    I'm not very clear on your doubts. I guess that if you can make a chart of your x y z-values, then you can yourself. See the attached example. I made a picture of a set of values. Instead of the constant I've used, you can read directly in your worksheet. I hope this helps.

    Kind regards
    Amine31

    (Bravo to give good answers, mark it as a Solution If your problem is resolved)

  • Get random errors and missing fonts after July 2011 service pack installation.

    Original title: July 2011 service pack... it completely trashed my software... How can I fix... I can't do system restore yet because no words to do

    I get random errors and missing fonts in all directions... everything was going well until the package of July tried to install it, and then everything went haywire.

    Hi KarenBillette,

    1 do you have. which Service pack tried to install?

    2 Windows operating system you are using?

    Method 1:

    You can try to remove the update from Windows update and check.

    Remove an update

    If this is not possible, then you can try to boot in safe mode and check if you can do a system restore.

    Method 2:

    Step 1: Try to start in safe mode.

    Start your computer in safe mode

    Step 2:

    You can try to perform a system restore to a point of restoration before the update was installed.

    Note: When you perform the system restore to restore the computer to a previous state, programs and updates that you have installed are removed.

    To run the system restore, you can consult the following links:

    System restore

    System Restore: frequently asked questions

    Hope this information is useful.

  • E/s files does not save the items in the table

    I can't save the items in the table. If I quit the program and restart it, the array starts at 0 again. I want it from the value at which it stopped.

    Is this a flaw in the Subvi "Timer A1"?

    Thanks for the help.

    mhaque

    Your feedback nodes are defined overall boot on the first call, as evidenced by the glyphs.  If you are stop and start your program, must be configured to initialize worldwide on the compilation or the load, simply right-click and change the setting.  This should give you the behavior you're looking for, but does not exclude the intrinsic problems with the code.

  • How to convert a table 1 d of cluster of 5 items in a table of numbers 2D? (a graph historical data)

    Hello

    in my vi, I have an array with 5 slots displaying measurement data.

    The user must be able to record all the data in the history of the card at any time. (for example the user looks at the picture and something happens, then it based on a 'save' - button)

    I know that I can read the data in the history with a property node. This isn't the problem. The problem is, how to deal with the data? The type of history data is a table 1 d of cluster of 5 elements.

    I convert these data somehow in a 2 D-table of numbers or strings, so that I can easily save it to a text file.

    How to convert a table 1 d of cluster of 5 items in a table of numbers 2D?

    I use LabVIEW 7.1

    Johannes

    Hallo Johannes,

    the photo shows the trivial way:

Maybe you are looking for