Ver Mensaje Individual
  #2 (permalink)  
Antiguo 14/12/2006, 11:32
MaxExtreme
 
Fecha de Ingreso: abril-2005
Mensajes: 3.083
Antigüedad: 19 años, 9 meses
Puntos: 17
Re: Problema con bibliotecas en C

Dudo muy mucho que "man" te diga que random() es de stdlib.h, puesto que no existe en ANSI-C.

La función que buscas es rand() Y sí, está en stdlib.h:

Código:
F:\>man random
No manual entry for random

F:\>man rand

RAND(3)                             NEWLIB                             RAND(3)

NAME
       2.29 `rand', `srand'--pseudo-random numbers

SYNOPSIS
            #include <stdlib.h>
            int rand(void);
            void srand(unsigned int SEED);
            int rand_r(unsigned int *SEED);

DESCRIPTION
       `rand' returns a different integer each time it is called; each integer
       is chosen by an algorithm designed to be unpredictable, so that you can
       use  `rand' when you require a random number.  The algorithm depends on
       a static variable called the "random seed"; starting with a given value
       of the random seed always produces the same sequence of numbers in suc-
       cessive calls to `rand'.

          You can set the random seed using `srand'; it  does  nothing  beyond
       storing  its  argument  in the static variable used by `rand'.  You can
       exploit this to make the pseudo-random sequence  less  predictable,  if
       you wish, by using some other unpredictable value (often the least sig-
       nificant parts of a time-varying  value)  as  the  random  seed  before
       beginning a sequence of calls to `rand'; or, if you wish to ensure (for
       example, while debugging) that successive runs of your program use  the
       same  "random" numbers, you can use `srand' to set the same random seed
       at the outset.

RETURNS
       `rand' returns the next pseudo-random integer in sequence; it is a num-
       ber between `0' and `RAND_MAX' (inclusive).

          `srand' does not return a result.

PORTABILITY
       `rand'  is required by ANSI, but the algorithm for pseudo-random number
       generation is not specified; therefore, even if you use the same random
       seed,  you  cannot expect the same sequence of results on two different
       systems.

          `rand' requires no supporting OS subroutines.

SEE ALSO
       rand is part of the libc library.  The full documentation for  libc  is
       maintained  as  a  Texinfo  manual.   If  info  and  libc  are properly
       installed at your site, the command

              info libc

       will give you access to the complete manual.

Última edición por MaxExtreme; 14/12/2006 a las 11:40