Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. C# shuffle one column out of two

C# shuffle one column out of two

Scheduled Pinned Locked Moved C#
csharpdatabasevisual-studiotutorial
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    yandroide
    wrote on last edited by
    #1

    Hi, I am having trouble shuffling a column out of two. This is my original table below in Ms Access.

    ID_EMPLOYEE ID_STATION
    ALAD DECH
    FRED DECI
    MIKE ORR
    PAM OR
    RAK ORW
    RAYN PROC

    I would like to shuffle ID_STATION and have something different at every run. For example:

    ID_EMPLOYEE ID_STATION
    ALAD ORW
    FRED PROC
    MIKE DECI
    PAM DECH
    RAK OR
    RAYN ORR

    I am using visual studio 2012 with c#. I created a List called scheduleList in my class SCHEDULE which contains properties like sEmployeeID and sStationID . I fill the list as follow:

    List scheduleList = new List();
    //Populating Schedulelist from database
    foreach (DataRow row2 in tschedule.Rows)
    {
    sEmployeeID = row2["ID_EMPLOYEE"].ToString();
    sStationID = row2["ID_STATION"].ToString();
    scheduleList.Add(new SCHEDULE(sEmployeeID, sStationID));
    }

    All I want now is a code to shuffle my ID_STATION only.

    L T 2 Replies Last reply
    0
    • Y yandroide

      Hi, I am having trouble shuffling a column out of two. This is my original table below in Ms Access.

      ID_EMPLOYEE ID_STATION
      ALAD DECH
      FRED DECI
      MIKE ORR
      PAM OR
      RAK ORW
      RAYN PROC

      I would like to shuffle ID_STATION and have something different at every run. For example:

      ID_EMPLOYEE ID_STATION
      ALAD ORW
      FRED PROC
      MIKE DECI
      PAM DECH
      RAK OR
      RAYN ORR

      I am using visual studio 2012 with c#. I created a List called scheduleList in my class SCHEDULE which contains properties like sEmployeeID and sStationID . I fill the list as follow:

      List scheduleList = new List();
      //Populating Schedulelist from database
      foreach (DataRow row2 in tschedule.Rows)
      {
      sEmployeeID = row2["ID_EMPLOYEE"].ToString();
      sStationID = row2["ID_STATION"].ToString();
      scheduleList.Add(new SCHEDULE(sEmployeeID, sStationID));
      }

      All I want now is a code to shuffle my ID_STATION only.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Create a table that holds "all possible values" or "testset" that can go into the ID_STATION, use RANDOM to fetch the values for your insert.

      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

      1 Reply Last reply
      0
      • Y yandroide

        Hi, I am having trouble shuffling a column out of two. This is my original table below in Ms Access.

        ID_EMPLOYEE ID_STATION
        ALAD DECH
        FRED DECI
        MIKE ORR
        PAM OR
        RAK ORW
        RAYN PROC

        I would like to shuffle ID_STATION and have something different at every run. For example:

        ID_EMPLOYEE ID_STATION
        ALAD ORW
        FRED PROC
        MIKE DECI
        PAM DECH
        RAK OR
        RAYN ORR

        I am using visual studio 2012 with c#. I created a List called scheduleList in my class SCHEDULE which contains properties like sEmployeeID and sStationID . I fill the list as follow:

        List scheduleList = new List();
        //Populating Schedulelist from database
        foreach (DataRow row2 in tschedule.Rows)
        {
        sEmployeeID = row2["ID_EMPLOYEE"].ToString();
        sStationID = row2["ID_STATION"].ToString();
        scheduleList.Add(new SCHEDULE(sEmployeeID, sStationID));
        }

        All I want now is a code to shuffle my ID_STATION only.

        T Offline
        T Offline
        thanh_bkhn
        wrote on last edited by
        #3

        You could do this as below: 1. Create a new List to store all values of ID_STATION 2. Use Random class to generate a random index from 0 to upper bound value of the above List 3. Add the value corresponding to this index into a new List 4. Remove the value from the old List 5. Repeat from 2 until the old List become empty. 6. Update every record in your table Update tableName set ID_STATION = stationList[i] where ID_EMPLOYEE = employeeList[i]

        "Never memorize something that you can look up." - Albert_Einstein

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups