Thread: How to generate random numbers between 65 and 75

  1. #16
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    It makes it an unsigned number. Default is int, U makes it unsigned, L long

    123U unsigned int
    123UL unsigned long int
    123L long
    123LL long long

    I think there was a post about this somewhere edit: yeah see --v
    Last edited by robwhit; 03-02-2008 at 01:47 AM.

  2. #17
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Indeed -- well, I made one anyway.

    http://cboard.cprogramming.com/showp...88&postcount=5
    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.

  3. #18
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by robwhit View Post
    It makes it an unsigned number. Default is int, U makes it unsigned, L long

    123U unsigned int
    123UL unsigned long int
    123L long
    123LL long long

    I think there was a post about this somewhere edit: yeah see --v
    OK, I thought it was something like that, but I've only seen 'f' used before for floating point numbers.
    Is the U actually required in that case, or would the compiler automatically assume you're talking about an unsigned number based on the context in which it's used?

  4. #19
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Integral promotion would promote, say, an int to an unsigned int. Basically, all operands of an expression are converted to the "largest" type, or widest, or whatever. signed char is the lowest, then unsigned char, then signed short, and so on, until unsigned long (or unsigned long long, if it exists); then float, then double.
    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. #20
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by cpjust View Post
    Although I'm sure the article is correct, I still have no idea why using (rand() % n) is wrong or what that whole thing about the low order bits was talking about? I also don't know why seeding it with time() wouldn't work very well (assuming you wait > 1 second between seeds)?
    Using rand() % n is not wrong. It has some issues you should be aware of.

    And the thing about lower order bits not being very random is outdated information, but still relevant on some old systems.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File IO
    By Jack1982 in forum C++ Programming
    Replies: 9
    Last Post: 10-15-2007, 01:14 AM
  2. binary data file
    By tucker81 in forum C Programming
    Replies: 8
    Last Post: 06-08-2006, 12:50 AM