RAND_MAX

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • yawnmoth

    RAND_MAX

    According to php.net, mt_rand() and rand()'s$max value is, by default,
    RAND_MAX. This suggests to me that RAND_MAX is a constant, however,
    the following PHP script shows this not to be the case:

    <?php
    echo defined('RAND_M AX') ? 'defined' : 'not defined';
    ?>

    Any ideas as to why this is?

  • Michael Fesser

    #2
    Re: RAND_MAX

    ..oO(yawnmoth)
    >According to php.net, mt_rand() and rand()'s$max value is, by default,
    >RAND_MAX. This suggests to me that RAND_MAX is a constant, however,
    >the following PHP script shows this not to be the case:
    >
    ><?php
    >echo defined('RAND_M AX') ? 'defined' : 'not defined';
    >?>
    >
    >Any ideas as to why this is?
    Just because something is written in caps in the manual doesn't
    necessarily mean that it's a PHP constant. It could also be a system-
    dependent constant in the C source code.

    Micha

    Comment

    • gosha bine

      #3
      Re: RAND_MAX

      yawnmoth wrote:
      According to php.net, mt_rand() and rand()'s$max value is, by default,
      RAND_MAX. This suggests to me that RAND_MAX is a constant, however,
      the following PHP script shows this not to be the case:
      >
      <?php
      echo defined('RAND_M AX') ? 'defined' : 'not defined';
      ?>
      >
      Any ideas as to why this is?
      >
      RAND_MAX is not a php constant, it's defined in the standard C library
      and is platform dependent. For example, on windows it's only 32767.



      --
      gosha bine

      extended php parser ~ http://code.google.com/p/pihipi
      blok ~ http://www.tagarga.com/blok

      Comment

      Working...