Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Craig O'Mahony 364 posts 918 karma points
    Mar 20, 2015 @ 14:19
    Craig O'Mahony
    0

    Randomly select nodes

    Hi all,

    I'm using a c# usercontrol and what I'm trying to do is randomly select a group of nodes. Basically I've a 'question' node and under this node there is a number of questions (child nodes) and what I want to do is select say 20 of these questions at random and load them into a datatable.

    I've got to the point where I can loop through all of the children and put them in a recordset but i'm don't know how to randomly select the nodes.

    Any help would be greatly appreciated.

    Thanks,

    Craig

  • Sören Deger 733 posts 2844 karma points c-trib
    Mar 20, 2015 @ 14:52
    Sören Deger
    0

    Hi Craig,

    you can do this with standard c# code. You can sort your list of childrens with the random function.

     

    Here is an general example:

    http://stackoverflow.com/questions/5383498/shuffle-rearrange-randomly-a-liststring

     

    Hope this helps.

    Best,

    Sören

  • Craig O'Mahony 364 posts 918 karma points
    Mar 20, 2015 @ 16:15
    Craig O'Mahony
    0

    Thank Soren,

    I know that I can randomise/sort the datatable itself but the problem that I have is that the datatable itself is being used for all sorts of nested relations and sorting on the table strips out the parent/child relations and naming conventions. Hence the question about randomly getting the node themselves and then I can build the table using these random nodes and keep the rest of my code intact.

    Any ideas?

    thanks,

    Craig

  • Sören Deger 733 posts 2844 karma points c-trib
    Mar 20, 2015 @ 16:49
    Sören Deger
    0

    Hi Craig,

    ok, that's not easy. Sorry, but I have no concrete idea for this. Perhaps you can make a copy of your recordset to a new list and randomise this list. But I think the relations between the copied list and your recordset can be very tricky. And without code it is not easy to imagine this.

     

    Cheers,

    Sören

Please Sign in or register to post replies

Write your reply to:

Draft