srand(time(NULL))

Discussion in 'C Programming' started by Ioannis Vranos, Mar 10, 2008.

  1. Ioannis Vranos

    Richard Guest

    K&R style is easily the most maintainable and easiest on the eye I have
    ever used. It just "makes sense. header, body, footer. e.g

    if(expr){
    expr;
    }
     
    Richard, Mar 10, 2008
    #21
    1. Advertisements


  2. LOL. I prefer the "more sense" to me

    if(expr)
    {
    /* ... */
    }

    style. :)
     
    Ioannis Vranos, Mar 10, 2008
    #22
    1. Advertisements


  3. Perhaps he formatted his hard disk at some time, and his backup was a
    bit old...
     
    Ioannis Vranos, Mar 10, 2008
    #23
  4. Ioannis Vranos

    santosh Guest

    This tends to waste vertical space. I tend to prefer your style for
    function's opening and closing brace and use the K&R style for other
    purposes, except for code blocks.

    foo()
    {
    if (condition) {
    /* ... */
    }
    else {
    /* ... */
    }

    {
    /* some code */
    }

    return;
    }
     
    santosh, Mar 10, 2008
    #24

  5. More space sometimes means more readable.



    I like complete consistency myself. You know how this stuff goes,
    everyone has his/her style.
     
    Ioannis Vranos, Mar 10, 2008
    #25
  6. santosh said:

    That's the disadvantage (for those who consider it so, of whom I am not
    one). The advantage (for those who consider it so, of whom I am very
    definitely one) is that the braces very obviously line up with each other,
    visually reinforcing one's perception of the block scope.

    <snip>
     
    Richard Heathfield, Mar 10, 2008
    #26
  7. Ioannis Vranos

    Default User Guest

    Yeah, I was unaware that vertical space was in short supply.
    My personal preference is Whitesmiths style:

    if(exp)
    {
    /* code */
    }

    The braces are part of the compound statement, and I like them at the
    same indent level as the code.

    Alas, the coding standard we use these days prefers your style, so I'm
    shifting even my personal code to that style.




    Brian
     
    Default User, Mar 10, 2008
    #27
  8. snip

    Keith this wouldn've worked before c99. What did people do before C99 ? In
    C89 if I'm right there was no time.h or time_t type. This answers a previous
    question of mine.

    Bill
     
    Bill Cunningham, Mar 10, 2008
    #28
  9. Both the <time.h> header and the time_t type are present in C89.
     
    Harald van Dijk, Mar 10, 2008
    #29
  10. Ioannis Vranos

    Randy Howard Guest

    Somewhere, in a dark whole, is someone still left on an 80x25 terminal.
    :)

    Get a widescreen monitor that supports rotation, and run it vertically.
    All the vertical space you need and then some.
     
    Randy Howard, Mar 10, 2008
    #30
  11. There's no way in hell you're a professional programmer bound by any
    coding standard at all - with your idiotic attitude you'd be drummed out
    of any shop I've ever experienced before you could say "don't top post".
     
    Antoninus Twink, Mar 10, 2008
    #31
  12. Is srand(time(NULL)); an effective solution for seeding rand(), or is
    If you use this approach to generate random numbers for a game of chance
    (such as, say, blackjack or craps) and make it available to the public
    to play for real money, you're going to go bankrupt.

    This is true for this method of seeding _any_ pseudo-random number
    generator.
     
    Gordon Burditt, Mar 11, 2008
    #32

  13. What is your suggestion?
     
    Ioannis Vranos, Mar 11, 2008
    #33
  14. Although the commandment talks about parameters, I can't
    help but notice the parallels with advice given to those
    who cast malloc in clc.

    No conforming compiler is allowed to _enforce_ prototypes,
    but those who deliberately prefer to use compilers with
    broken conformance in this regard are chastised heavily
    for doing so.
     
    Peter Nilsson, Mar 11, 2008
    #34
  15. Ioannis Vranos

    santosh Guest

    Bill Cunningham wrote:

    No, both time.h and time_t were there in C89. And the same method that
    Keith explained will work for all versions of standard C.
     
    santosh, Mar 11, 2008
    #35
  16. Is srand(time(NULL)); an effective solution for seeding rand(), or is
    Use specialized (and probably expensive) hardware based on physics
    that is currently believed to be true random due to quantum effects.
    This includes things like detection of radioactive decay and thermal
    noise of a reverse-biased diode. Some processors (certain models
    of Intel Pentium) have this built in, but I'm not sure how good it
    is.

    Also, use a seed much bigger than 32 bits. And you probably want to
    use the time down to picoseconds.

    Keystroke timing probably doesn't alone provide enough randomness
    for online gambling with real money.
     
    Gordon Burditt, Mar 11, 2008
    #36
  17. Ioannis Vranos

    Morris Dovey Guest

    Hmm. I see a light up there. Hellooo?

    The link below leads to my latest project. Scroll to the bottom
    of the page...

    :-D
     
    Morris Dovey, Mar 11, 2008
    #37
  18. Ioannis Vranos

    Default User Guest

    I still use them when I telnet in places. That just seems the "right"
    size for that.




    Brian
     
    Default User, Mar 11, 2008
    #38
  19. Ioannis Vranos

    santosh Guest

    Well, for my personal programming I prefer 80x25 text mode, because I
    find that it minimises eye strain. I also prefer text mode due to long
    years with DOS and UNIX (without X).

    Most workplaces here are still full of old CRTs with terrible flicker,
    set inappropriately to something like 1024x768, minimising the refresh
    rate.
     
    santosh, Mar 11, 2008
    #39
  20. [/QUOTE]
    It was too small 30 years ago and it's too small now.

    -- Richard
     
    Richard Tobin, Mar 11, 2008
    #40
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.