Choose a random element of array 2D

I have a 2D integer array. I want to randomly select an element of the array. It's easy - just generate 2 random numbers and the array index.

Here is the twist. I want to be more likely to be chosen over their value is compared to the rest of the elements of the elements. It is a memory game.

If all items contain the same value the probability of a being selected is the same as any other. If an element has a value greater than all the others, then it is most likely to be chosen. If an element has a value less than all the others, then it is less likely to be chosen. Finally if an element contains a value of zero, then it will be never chosen.

The only way I can think to do is by using a table 1 d of the clusters of x and y to be used for indexing table 2D. I would like to browse the table 2D. For each item, I read the value and which create several x, y clusters blacklisted in course and insert them into the 1 d of the index table. Now I just generate a random number of the 1 d array index, then the 2D of the index table. I'd probably have to "shuffle" 1 d of the index table, would I?

It seems a bit Rube Goldberg and I hope someone can come up with a simpler method.

This is a project very rough. Modify if needed.

(probably need a few tweaks)

Tags: NI Software

Similar Questions

  • How to change the sizes of elements of array programmatically?

    Hi all

    I have a small question about changing the size of the elements in the array. I hope someone can help, because I am in a bind!

    I connect certain intensities of a range of fibers using a camera. For the calibration of the system, I gain a picture of the camera, click on the image points to divide it into areas of interest. I have my image to overlay with a grid indicating the areas of interests - for example a 4 x 6 picture. I then have to select fibers - or Kings - I want to connect from.

    I have a cluster type-def (a number and a Boolean value) to specify the number of fibers and to enable logging of this fibre power. I superimpose a (transparent) picture of this typedef on my image to correspond with the regions of interest. So here's my problem - I want to change the dimensions of the table for each control corresponds to my KING. I can resize the elements of law on the elements on the façade, but couldn't find a way to do it programmatically. The array property node > element of array > limits don't "change to write" it's the first thing I tried.

    Its only really important elements alignment with my Kings - so adding in the gaps/spacing programmatically would also work for me... goal again once I can't understand how to do this! I've attached a screenshot of part of my image with table superimposed to show you all exactly what is my problem.

    Thanks in advance for you help,

    Dave

    PS I'm under Labview 8.6 without adding vision on.

    Here is my cheat (and cheap) way if you want to get fancy and Center digital indicators and booleans, you could add shims on the North and west sides, too.

  • WMP plays not music in good order-WMP seems to choose items randomly

    My playlist that I am about to make a CD does not record the music in the order I want.  WMP seems to choose items randomly. How can I get my list has played at the top of the list I chose.

    EUREKA!      Oh, Umesh P you have solved my problem.   Now works perfectly.    I may have updated 2010 but don't really know what version of WMP, I (come with XP 2005) I made many CDs & ripped music & have playlists.    Sometimes the songs that I select cannot be read because the player says they are used elsewhere so in this case I'm removing them from my makiong of playlists that I always have them in a folder.   I'm really not very good even if I was storing a lot of music years truly his trial & error but I didn't know that "shuffle" involved despite pick them up with the help.

    I am very grateful and thank you so much you are a 10 +.
  • change the property of element in array for 'initialized '.

    I'm a newcomer here. And it's a simple question.

    The objective of this part is to record the data in the table.

    You can see that if the array element is not initialized, it will be not recorded in the worksheet, which saves space in the disk. So change the property 'initialized' of this feedback to unitialized array element?

    Thank you

    You can "right click on the item of data operations remove the element.

    (This has nothing to do with "uninitialized". The size of the array is indicated by the light elements, the dull items fall outside the valid range, which has nothing to do with the size of the container. Your first table has two components and that your second table has three elements).

  • Move the cursor to data entry in the first element of array

    It seems that it should be simple, and that I still can't find a way to do this.

    I want to have a dialogue VI with a single Berry. When loading of the dialog, I want the data entry cursor to appear in the first element of the array, so the user can begin to enter data with the keyboard and I can't click on it with the mouse and then tab on the rest of the table. The property node 'Key Focus' just seems to give me a box around the entire table without any cursor active data entry.

    A table control has a property called array element. Get a reference to it and its main objective set to true. I just spent a few minutes test this and it didn't work for me if I first got the reference, then turn the key a second property node, rather than doing everything in one implicit property node. In addition, it still affects the update to the second element of the array, which is certainly not too useful. I have not found a way around that in my brief tests, unfortunately.

  • elements of array Dublicate

    Hallo,

    I can't really explain my problem, but my example will normally clear...

    (I have an array of random size: 4-4, 10-3,... and random values)

    Thanks for your help!

    in:

    1 2 3 4

    5 6 7 8

    9 10 11 12

    departures:

    1 1 2 2 3 3 4 4

    5 5 6 6 7 7 8 8

    9 9 10 10 11 11 12 12

    Nathand indeed

  • elements of array equal between them?

    Hello

    Maybe a simple question, but I have not found the answer here...

    I have a D 1 table with us will tell the 4 elements, and if all things are equal to each other

    (1,1,1,1) then it should return true

    If an item is then the rest of the others

    Computing (1,2,1,1) should return false...

    How to build this simple?

    Best regards

    Thijs

    Hey Taylor,

    We must compare each element of the array array1 is member of the array array2:

    Did I get that right?

    Edit: the label of the output should be just "all the elements of the array are members of the array array2."

  • CREATING RANDOM ELEMENTS

    THE MAGICAL TEXT INITIALIZED ABCD, AND I NEED TO CREATE 50 ELEMENTS RANDOM FROM THIS TEXT... CAN SOMEONE HELP ME


  • Dynamically control the size (in pixels) of elements of array?

    Hey everybody,

    I am writing a great vi where space façade becomes a limitation.   One of the elements I want to display is an array of Boolean flags (rectangular LED) 2D.  Is it possible to dynamically resize the elements of the array so that regardless of the number of items, the whole picture is still visible and has a constant print.  For example, the table is 8 x 8 elements and includes 160 x 160 pixels in front for each element is about 20 x 20 pixels.  Then, the number of items passes to the 4 x 4.  I want the display to stay 160 x 160 pixels, but the size of each element double 40 x 40 pixels.  Is this possible?

    Thank you all,

    Matt

    The solution graphic intensity is probably a little bit simpler. Here is an example. (The advantage is that the limits of the graphic remaining completely static).

  • Table of elements - multidimensional arrays

    Need:

    I need a multidimensional array that I want to use through several workflow.

    Detail:

    The information for each of the 10 + child tables are attributes of static information of VC:objects as VC:sdkconnection, VC:DatacenterFolder, VC:NetworkFolder, VC:Datacenter, etc.

    Direction:

    My idea was to create a configuration for each of the table element.  Then, create a Parent Configuration element with an attribute type of elements in the Configuration table.  To test this I wanted to make one for each loop through the array of items.

    System.log("Total Number of array objects: " + ParentElement.length);
    for(var i=0; i<ParentElement.length; i++){
      System.log("Total Number of array objects name " + ParentElement[i].name);
      System.log("Total Number of array objects: " + ParentElement[i].length) 
    }
    

    I managed to print the names of the child element objects.

    I have been unsuccessful in obtaining listing attributes in the child objects.

    in the above code ParentElement [i] .length is undefined.

    Advice/guidance is appreciated.

    Even if your solution does not work, it gives me a new direction.  And ultimately a solution.  Without identifying each brick on the yellow brick road, here's what I came with.

    1. I moved all configuration items in a folder to create a category

    2 pulled all the elements (previous method began with an attribute of the element to set up an array of elements).

    3. by looping through the items looking for a match in the entry workflow a string to index into the items attribute

    4. once found populate the output of the workflow with the objects identified in this configuration item.

    It was exactly what I was looking for when I started this thread, but it gives me a dynamic solution for future growth.  If I need to extend my environment, I can do this simply by adding another element of configuration category and revisits not 100s of workflows.

    Thank you for your quick response, the expertise and the entrance.

    var class = Server.getConfigurationElementCategoryWithPath (categoryPath);

    If (category == null) {}

    throw "CI" "" + categoryPath + "' not found!";

    }

    var category.configurationElements = items;

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

    If (elements [i] .name! = null) {}

    var attribute is elements [i] .getAttributeWithKey ("indexCode");.

    indexCode = attribute.value;

    If (attribute! = null) {}

    If (attribute.value == inputCode) {}

    attribute = elements [i] .getAttributeWithKey ("vc_sdk");

    vc_sdk = attribute.value;

    attribute = elements [i] .getAttributeWithKey ("vc_Datacenter");

    vc_Datacenter = attribute.value;

    attribute = elements [i] .getAttributeWithKey ("vc_hostsFolder");

    vc_hostsFolder = attribute.value;

    attribute = elements [i] .getAttributeWithKey ("vc_NetworkFolder");

    vc_NetworkFolder = attribute.value;

    attribute = elements [i] .getAttributeWithKey ("vc_DatastoreFolder");

    vc_DatastoreFolder = attribute.value;

    break;

    }

    }

    }

  • 2: Sequentially all an elements of array, display one after the other

    Hello!

    This is a new start for another thread (http://forums.adobe.com/message/4897959#4897959).

    (ActionScript 2 ONLY)

    My site is a SWF that loads on the user requests data from a database of MySQL via PHP.

    I have no problem to control the whole communication process.

    On the homepage, as well as new which are already presented in the main part of the right side of the page, I want to display on the left side a few reminders of the essential services and also registered users of mandatory measures must do when visiting the site.

    DB returns: an array with one. separator and the total of the items in the array.

    In Flash, I use the following function to get the picture:

    remindersFct = function () {}

    var myReminders = new LoadVars();

    myReminders.identity = "reminders";

    myReminders.onLoad = {function (ok)}

    If {(ok)

    _root.reminderFld.html = true;

    var myArray:Array = new Array (myReminders.mydata.split("|"));

    myArray.length = myReminders.totalItems;

    }

    else {}

    Stop();

    }

    };

    myReminders.sendAndLoad ("misc.php", myReminders, 'POST');

    };

    remindersFct (); start the process

    I want to know different things...:

    1 - How can I 'explode' this table in its different elements (all are text strings)

    2. so, how can I know the SWF to view them, one after the other, in the field appropriate htmlText

    3. How can I adjust the length of each of these items, based on the length of the text they contain

    Thank you very much in advance for your help!

    Just another thing.  Given that you call the setTimeout for both halves of the conditional, it means that you don't need in the conditional and can move around outside, and you don't need in the first half of the conditional either...

    counter ++;

    Sto var = setTimeout (displaytext, delay);

    If (counter == theText.length) {}

    counter = 0;

    }

  • Choose a random instance name

    Hey, I want to make a random item visible

    How can I do

    can you give me a code example



    Thank you

    Hi fastboy,.

    [Maybe in general debates AS3]

    If you want a random item, you need to know what group/list.

    Keep a table elements that you create in order to later take an item randomly from this list:

    //

    myArray [Math.floor (Math.Random () * myArray.length)]

    Otherwise (if items are not placed with code), you can check the number of items is as a child of the container and use something like:

    container.getChildAt (Math.floor (Math.Random () * container.numChildren))

    Kind regards

    Manno

  • No. random store in array

    Hi guys,.

    I want to chance only between 1 to 15 of store in my table.

    but this time not repeat all the no.

    for example myArray (4,6,8,9,2,3,5,1,7,10,13,15,12,11)

    can you check my code.

    ******************************************************

    var randomNo:Number;

    var holdArray:Array = new Array();

    for (var i: Number = 0; i < 15; i ++)

    {

    randomNo = Math.round (Math.random () * (15-1)) + 1;

    holdArray.push (randomNo);

    }

    ******************************************************

    Thank you

    JaxNa

    Your code will be repeated values randomly.  Try instead the following...

    var holdArray:Array = new Array (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);

    function shuffle (a) {}
    var p;
    var t;
    Ivar var;
    for (ivar =. Length-1; Ivar > = 0; Ivar-) {}
    p = Math.Floor ((Ivar+1) * Math.Random ());
    t = a [ivar];
    a [ivar] = a [p];
    a [p] = t;
    }
    }

    Shuffle (holdArray);

    trace (holdArray);

  • Element of array nested using myIdName access - is it possible?

    Hello

    I have a nested table containing a series of 2 tables of element containing an object name and the text associated with this object.

    I've set up like this:

    [public var name: Array = [['instance 1 name', 'text for first object'], ['2 instance name', 'text for the second item'],...]] ;

    What I'm trying to do is have the text for the object appears in a text box when the object is moved.

    It is all set up within a class that contains the code for the functions of drag / move.

    If I set the text box to display a specific item, such as:

    MovieClip (parent).text_box.text = names [2] [1];

    It works very well. But I can't seem to create the value of the first installment of the myIdName attribute.

    I had to work for 2 bays - one with the name and the other with text where the code was;

    MovieClip (parent).text_box.text = texts [names.indexOf (this.name)];  (tables named 'name' and 'texts', named 'Text_box' text box)

    I hope that there is something similar that I can do for the nested table, but what I'm trying to gives me error #1010 - term undefined.

    Is there an easy way to sort this out - or am that I better stick with version 2 of table?

    (BTW, this is my first shot at the use of tables)

    Thank you

    Why not use an object to do this, such as:

    var oTexts:Object = {}

    "clipname1": "text to clip 1".

    "clipname2": "text to Chuck 2".

    "clipname3": "text to clip 3".

    }

    and then just use sometihing like this

    var txt:String is MovieClip (parent) .oTexts [myIdName];.

    etc...

  • The mx prefix for the element mx:Array is not bound

    Hi all

    I have a component:

    <? XML version = "1.0" encoding = "utf-8"? >

    "< mx:Array id ="stop""">

    "" < mx:Object label = "Flex"

    " thumbnailImage ="http:/someURL "" "

    " fullImage = ' http://someURL " />

    < / mx:Array >

    < mx:Canvas ' xmlns:mx = ' http://www.Adobe.com/2006/MXML ">

    < / mx:Canvas >

    It gives me an error

    The prefix "mx" for the "mx:Array" element is not bound

    I need a root here, but I can't use mx:Canvas, what would be the best choice?

    see you soon

    Luca

    Hi Luca,

    Try to put the picture inside your canvas, rather than outside...


    http://www.Adobe.com/2006/mxml">

    thumbnailImage = "http:/someURL."

    fullImage ="http://someURL" / > "


    Why you don't want to use mx:Canvas as the root of your component Locator...? However the component no matter what you use try to put the your tag inside your component root, otherwise you will be lifted the same error as indicated. The error occurs as the compiler does not recognize the namespace mx for the table since you declared outside the root of your component.

    Thank you

    Jean Claude

Maybe you are looking for