Flash a random number

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • APmore
    New Member
    • Jul 2007
    • 14

    Flash a random number

    Hi all,

    How to flash a random number in c/c++?

    Kindly help...

    Regards,
    Kishore
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by APmore
    How to flash a random number in c/c++?
    flash a random number?

    kind regards,

    Jos

    Comment

    • APmore
      New Member
      • Jul 2007
      • 14

      #3
      Originally posted by JosAH
      flash a random number?

      kind regards,

      Jos
      I mean to blink a random number on screen for every 10ms...


      Ok?

      Thanks,
      kishore

      Comment

      • boxfish
        Recognized Expert Contributor
        • Mar 2008
        • 469

        #4
        Blink a random number on the screen? Do you want to show this number in the console, just printed with cout?

        Comment

        • APmore
          New Member
          • Jul 2007
          • 14

          #5
          Originally posted by boxfish
          Blink a random number on the screen? Do you want to show this number in the console, just printed with cout?
          yaa blink the number on console

          Comment

          • boxfish
            Recognized Expert Contributor
            • Mar 2008
            • 469

            #6
            Pseudocode goes something like

            Code:
            while (true) {
                wait for 10 ms
                generate random number
                display number
                wait for 10 ms
                backspace number
            }
            Which of these things are you having trouble with?

            Comment

            • APmore
              New Member
              • Jul 2007
              • 14

              #7
              Originally posted by boxfish
              Pseudocode goes something like

              Code:
              while (true) {
                  wait for 10 ms
                  generate random number
                  display number
                  wait for 10 ms
                  backspace number
              }
              Which of these things are you having trouble with?
              How to wait for 10ms exactly?

              Comment

              • boxfish
                Recognized Expert Contributor
                • Mar 2008
                • 469

                #8
                the clock() function from the <ctime> include file tells you how many clock ticks have passed since your program was launched. You can divide it by CLOCKS_PER_SEC to get this length in seconds. I would define a constant
                CLOCKS_PER_10MS = CLOCKS_PER_SEC / 100;
                So to wait for 10MS, Take the current clock value, add CLOCKS_PER_10MS to it, and use a while loop to wait for clock to be greater than that value. It should actually be very similar to the wait() function in the example on the page I linked to.
                I hope this is helpful.

                Comment

                • APmore
                  New Member
                  • Jul 2007
                  • 14

                  #9
                  Originally posted by boxfish
                  the clock() function from the <ctime> include file tells you how many clock ticks have passed since your program was launched. You can divide it by CLOCKS_PER_SEC to get this length in seconds. I would define a constant
                  CLOCKS_PER_10MS = CLOCKS_PER_SEC / 100;
                  So to wait for 10MS, Take the current clock value, add CLOCKS_PER_10MS to it, and use a while loop to wait for clock to be greater than that value. It should actually be very similar to the wait() function in the example on the page I linked to.
                  I hope this is helpful.
                  Yaa ..I think this is a good alternative..

                  Keep it up!!

                  Thanks,
                  Kishore

                  Comment

                  Working...