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
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Create Random number

Create Random number

Scheduled Pinned Locked Moved C / C++ / MFC
c++tutorialquestionlounge
15 Posts 7 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 Maximilien

    what about the mouse position ? if you use it, it will not be random anymore ...


    Maximilien Lincourt Your Head A Splode - Strong Bad

    H Offline
    H Offline
    Halawlaws
    wrote on last edited by
    #6

    yes because if u open the dialog and move it u will have different position of mouse also on each different computer it will be different /\|-||\/|/\|)

    M 1 Reply Last reply
    0
    • E Eytukan

      convert the random number to string and split into two..make them again as int. multiply one part of the number with Cpoint's x and others's with another (y + another Random number) ..he he :confused: vivek

      H Offline
      H Offline
      Halawlaws
      wrote on last edited by
      #7

      how to get the mouse position? /\|-||\/|/\|)

      1 Reply Last reply
      0
      • H Halawlaws

        yes because if u open the dialog and move it u will have different position of mouse also on each different computer it will be different /\|-||\/|/\|)

        M Offline
        M Offline
        Maximilien
        wrote on last edited by
        #8

        so ? what exactly you want to do ? ( besides the random numbers ) .


        Maximilien Lincourt Your Head A Splode - Strong Bad

        H 1 Reply Last reply
        0
        • M Maximilien

          so ? what exactly you want to do ? ( besides the random numbers ) .


          Maximilien Lincourt Your Head A Splode - Strong Bad

          H Offline
          H Offline
          Halawlaws
          wrote on last edited by
          #9

          The software allow users to create random serial number for there companies based on the serial number of the product. This random number is sold later if a certain client need to enable something in his device. /\|-||\/|/\|)

          M D 2 Replies Last reply
          0
          • H Halawlaws

            The software allow users to create random serial number for there companies based on the serial number of the product. This random number is sold later if a certain client need to enable something in his device. /\|-||\/|/\|)

            M Offline
            M Offline
            Maximilien
            wrote on last edited by
            #10

            why do you want to use the mouse position ? just generate the number with srand ( or rand, or some other methods ) and be done with it.


            Maximilien Lincourt Your Head A Splode - Strong Bad

            H 1 Reply Last reply
            0
            • M Maximilien

              why do you want to use the mouse position ? just generate the number with srand ( or rand, or some other methods ) and be done with it.


              Maximilien Lincourt Your Head A Splode - Strong Bad

              H Offline
              H Offline
              Halawlaws
              wrote on last edited by
              #11

              i need to complicate it so the user cannot use the usual function of C++ to generate such a code /\|-||\/|/\|)

              D C 2 Replies Last reply
              0
              • H Halawlaws

                The software allow users to create random serial number for there companies based on the serial number of the product. This random number is sold later if a certain client need to enable something in his device. /\|-||\/|/\|)

                D Offline
                D Offline
                David Crow
                wrote on last edited by
                #12

                You'd be better off using a GUID for this. You can use the guidgen.exe utility, or use CoCreateGuid() if you need it at run-time. The algorithm is already established, plus you cannot achieve true randomness with rand(), or any other function for that matter.


                "One must learn from the bite of the fire to leave it alone." - Native American Proverb

                1 Reply Last reply
                0
                • H Halawlaws

                  i need to complicate it so the user cannot use the usual function of C++ to generate such a code /\|-||\/|/\|)

                  D Offline
                  D Offline
                  David Crow
                  wrote on last edited by
                  #13

                  The odds of that happening would be 1 in 32,768.


                  "One must learn from the bite of the fire to leave it alone." - Native American Proverb

                  1 Reply Last reply
                  0
                  • H Halawlaws

                    i need to complicate it so the user cannot use the usual function of C++ to generate such a code /\|-||\/|/\|)

                    C Offline
                    C Offline
                    Chris Losinger
                    wrote on last edited by
                    #14

                    if the user is smart enough to watch your code call srand, he's smart enough to watch your code get the current mouse position. Cleek | Image Toolkits | Thumbnail maker

                    1 Reply Last reply
                    0
                    • H Halawlaws

                      How to create a random number not only using the MFC function but using the current time of generation and the mouse position? It should be impossible to crack /\|-||\/|/\|)

                      K Offline
                      K Offline
                      knapak
                      wrote on last edited by
                      #15

                      Hello In my opinion, a better way to do what you need is to use one of the random number generator routines in "NUMERICAL RECIPIES": http://www.library.cornell.edu/nr/cbookcpdf.html Scroll down to Ch. 7 in that page and you'll find a lot of algorithms that will be by far better you can come up using only your machine generator. You'll still need it, but the algorithms provide better "randomness" in your numbers and they are sorted by the way you need them to have certain statistical distributions. If you need them to have equal probabilities, then use the ran2 algorithm. This code is an implementation of it: seed = 0; srand (time(NULL)); rand(); seed = rand(); return ran2(seed); The return number is a uniform random deviate between 0 and 1. If you need integers just multiply your number as needed and take the integer. Cheers

                      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