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. srand(time(NULL)); in MSDN 2010

srand(time(NULL)); in MSDN 2010

Scheduled Pinned Locked Moved C / C++ / MFC
help
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.
  • M Offline
    M Offline
    mrby123
    wrote on last edited by
    #1

    I got the following compile error message, for using: srand(time(NULL)); warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data Thanks

    D A 2 Replies Last reply
    0
    • M mrby123

      I got the following compile error message, for using: srand(time(NULL)); warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data Thanks

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

      It's not an error, but a warning. Try:

      srand((unsigned) time(NULL));

      "One man's wage rise is another man's price increase." - Harold Wilson

      "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

      "Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous

      1 Reply Last reply
      0
      • M mrby123

        I got the following compile error message, for using: srand(time(NULL)); warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data Thanks

        A Offline
        A Offline
        Albert Holguin
        wrote on last edited by
        #3

        As already stated, it's not an error but a warning. Compiler is simply making sure you're doing it on purpose and not by mistake, remember that casting may lead to digits being dropped and rounding (hence the warning). Cast the data to the appropriate type and the compiler won't warn you about it anymore.

        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