4 Replies Latest reply on Apr 15, 2009 10:00 AM by Mylenium

    Stock market board animation...help

    Level 1

      I am trying to create a virtual stock market board in CS3 at the moment and am stuck on one thing:

      Randomising numbers. I want the numbers to randomly change and was looking for advice on how I would go about this?

       

      I know it is quite random, but any help would be absolutely awesome.

      So far I am using text...and thats it. Nothing too complex.

      I am a newbie too

        • 1. Re: Stock market board animation...help
          Rick Gerard Adobe Community Professional & MVP

          One easy way to do this is to use an expression to generate a random whole number. Simply add an empty text layer, then spin down layer properties and add this expression to the Source Text property:

           

           

          pause = .5; // seconds

          seed = Math.floor(time/pause);

          seedRandom(seed, true);

          n = random(0, 9);

          Math.round(n)

           

          • The first line sets a value in seconds for the time between number changes.
          • The second line divides comp tie by the pause value to generate a value for the random seed and rounds that number to an integer.
          • The third line tells the random number generator to use the seed you've generated.
          • The fourth line sets the value to the random number between 0 and 9.
          • The last line rounds the random number to an integer

           

          You could also write the expression like this:

           

           

          seedRandom(Math.floor(time/.5), true);

          Math.round(random(0, 9))

           

          But it's much more difficult to tell what's going on when you're just getting started.

           

          Now you've got a number between 0 and 9 that changes every half second that you can incorporate into a design. Each duplicate will be a different random number. You can change the pause value for each duplicate so that the numbers are not all changing at the same time. You can also vary the range so that some numbers are between 1 and 3 for example.

           

          I hope this helps.

          • 2. Re: Stock market board animation...help
            Mylenium Most Valuable Participant

            If you want your values to be not so random, you can also pull them from arrays:

             

            random([0,1,2,500,505,600])
            

            Furthermore, also consider that you usually want to show a variability on some base value as opposed to jumping all across the board, so use something like this:

             

            sChange=0.5; //change time
            
            seedRandom=Math.floor(time/sChange);
            
            sVar=50; //variation
            sBase=300; //base value
            
            sOut=sBase+Math.round(random(-sVar,sVar));
            
            [sOut]
            

             

            Mylenium

            • 3. Re: Stock market board animation...help
              Rick Gerard Adobe Community Professional & MVP

              I noticed a typo in Mylenium's expression. The random seed line should be:

               

              seedRandom(Math.floor(time/sChange), true);
              
              

              His expression is also a little more elegant than mine.

               

              Good luck.

              • 4. Re: Stock market board animation...help
                Mylenium Most Valuable Participant

                *oops* Thanks for the correction, Rick. ;-)

                 

                Mylenium