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. Help here...allow the files display randomly

Help here...allow the files display randomly

Scheduled Pinned Locked Moved C#
helptutorialquestion
6 Posts 4 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.
  • M Offline
    M Offline
    Missy Glory
    wrote on last edited by
    #1

    Hi everyone:), I have a problem here, my program can automatic display 12 files when the button is click.I use timer to let the 12 files to display orderly. But my question is " How to allow the 12 files to display randomly everytime when i click the button" :confused: :laugh:Thank for helpin

    T 1 Reply Last reply
    0
    • M Missy Glory

      Hi everyone:), I have a problem here, my program can automatic display 12 files when the button is click.I use timer to let the 12 files to display orderly. But my question is " How to allow the 12 files to display randomly everytime when i click the button" :confused: :laugh:Thank for helpin

      T Offline
      T Offline
      Tamimi Code
      wrote on last edited by
      #2

      could you explain more ??

      When you get mad...THINK twice that the only advice Tamimi - Code

      M 1 Reply Last reply
      0
      • T Tamimi Code

        could you explain more ??

        When you get mad...THINK twice that the only advice Tamimi - Code

        M Offline
        M Offline
        Missy Glory
        wrote on last edited by
        #3

        Yes... The 12 files is the 12 waveform to be display one by one automatically when i click the button.My program can only allow the 12 waveform to display in order when i run the program( everytime when i run the program, the 12 waveform will display from 1 to 12). Therefore my problem is " how to allow the 12 waveform to display randomly." for example when i run the program, the third waveform will run first. And when i run the program the second time, the tenth waveform will run first. Hope u understand..;) thank..

        J 1 Reply Last reply
        0
        • M Missy Glory

          Yes... The 12 files is the 12 waveform to be display one by one automatically when i click the button.My program can only allow the 12 waveform to display in order when i run the program( everytime when i run the program, the 12 waveform will display from 1 to 12). Therefore my problem is " how to allow the 12 waveform to display randomly." for example when i run the program, the third waveform will run first. And when i run the program the second time, the tenth waveform will run first. Hope u understand..;) thank..

          J Offline
          J Offline
          joon vh
          wrote on last edited by
          #4

          this is what I think you need:

                  static void Main(string[] args)
                  {
                      RunRandomly(12);
                  }
          
                  static void RunRandomly(int amount)
                  {
                      ArrayList alreadyused = new ArrayList();
                      Random rnd = new Random();
                      while (amount > 0)
                      {
                          int rndint = Convert.ToInt32(rnd.Next(12));
                          if (!alreadyused.Contains(rndint))
                          {
                              Run(rndint);
                              amount--;
                              alreadyused.Add(rndint);
                          }               
                      }
                  }
                  static void Run(int number)
                  {
                      // do whatever you need to do, number will be a random number between 0 and 11
                      Console.WriteLine(number);
                  }
          

          if it doesn't make sense, then neither did your question I'm afraid ;)


          Visual Studio can't evaluate this, can you? public object moo { __get { return moo; } __set { moo = value; } }

          S 1 Reply Last reply
          0
          • J joon vh

            this is what I think you need:

                    static void Main(string[] args)
                    {
                        RunRandomly(12);
                    }
            
                    static void RunRandomly(int amount)
                    {
                        ArrayList alreadyused = new ArrayList();
                        Random rnd = new Random();
                        while (amount > 0)
                        {
                            int rndint = Convert.ToInt32(rnd.Next(12));
                            if (!alreadyused.Contains(rndint))
                            {
                                Run(rndint);
                                amount--;
                                alreadyused.Add(rndint);
                            }               
                        }
                    }
                    static void Run(int number)
                    {
                        // do whatever you need to do, number will be a random number between 0 and 11
                        Console.WriteLine(number);
                    }
            

            if it doesn't make sense, then neither did your question I'm afraid ;)


            Visual Studio can't evaluate this, can you? public object moo { __get { return moo; } __set { moo = value; } }

            S Offline
            S Offline
            Stefan Troschuetz
            wrote on last edited by
            #5

            joon vh. wrote:

            int rndint = Convert.ToInt32(rnd.Next(12));

            No need to call Convert.ToInt32 here since Random.Next returns an integer.


            "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

            www.troschuetz.de

            J 1 Reply Last reply
            0
            • S Stefan Troschuetz

              joon vh. wrote:

              int rndint = Convert.ToInt32(rnd.Next(12));

              No need to call Convert.ToInt32 here since Random.Next returns an integer.


              "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

              www.troschuetz.de

              J Offline
              J Offline
              joon vh
              wrote on last edited by
              #6

              wow... dunno why I assumed it didn't :p good call


              Visual Studio can't evaluate this, can you? public object moo { __get { return moo; } __set { moo = value; } }

              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