Sleep(rand()%7000); ??

This is a discussion on Sleep(rand()%7000); ?? within the C++ Programming forums, part of the General Programming Boards category; should this work Code: Sleep(rand(7000)%7000); Sleep for 7000 + random 7000 its not working for me it the way, am ...

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    43

    Sleep(rand()%7000); ??

    should this work

    Code:
    Sleep(rand(7000)%7000);
    Sleep for 7000 + random 7000

    its not working for me it the way, am doing this incorrect?
    it doesen' t give me an error it just doesn't sleep as long as its supost to



    its the same thing as this i think, but I'm trying to put them both into one

    Code:
    Sleep(7000);
    Sleep(rand()%7000);
    Iím Dyslexic and I know that I donít spell well so quit telling to learn my English because I do my best at it all right.

    Windows XP with Dev-C++ for now.

  2. #2
    Registered User
    Join Date
    Nov 2005
    Posts
    673
    Code:
    Sleep((rand()%7000)+7000);
    that should work

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,305

    Question

    It doesn't give you any errors?!?!
    Nothing like this comes up when compiling?
    Code:
    error C2660: 'rand' : function does not take 1 arguments
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Quote Originally Posted by iMalc View Post
    It doesn't give you any errors?!?!
    Nothing like this comes up when compiling?
    Code:
    error C2660: 'rand' : function does not take 1 arguments
    No, it wouldn't say anything like that if warnings were disabled and <stdlib.h>/<cstdlib> was not included. I'd imagine you'd get something like "warning: implicit declaration of function `rand'", but perhaps not.

    So, my suggestion to JordanCason is to #include <stdlib.h> or <cstdlib>, since it seems you haven't already.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  5. #5
    Registered User
    Join Date
    Apr 2006
    Posts
    2,041
    Quote Originally Posted by dwks View Post
    No, it wouldn't say anything like that if warnings were disabled and <stdlib.h>/<cstdlib> was not included. I'd imagine you'd get something like "warning: implicit declaration of function `rand'", but perhaps not.

    So, my suggestion to JordanCason is to #include <stdlib.h> or <cstdlib>, since it seems you haven't already.
    Arn't implicit declarations only in C?
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  6. #6
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Apparently not.
    http://ugweb.cs.ualberta.ca/~rod/tut...messagesC.html
    http://www.thescripts.com/forum/thread128453.html

    You're right, though. In C you usually get "implicit declaration of function" warnings, and in C++ you usually get something like "no match for function call" or something. Whatever, there should be a warning of some kind.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  7. #7
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,633
    Well, Visual Studio throws a fit in that example. If it can't find the function or symbol, it will complain.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21