Posibles librerìas: Stdlib RAND( ) (Función) Ejemplo Vea también Devuelve un número aleatorio entre 0 y 1. Sintaxis RAND([nValorSemilla]) Tipos devueltos Numeric Argumentos nValorSemilla Especifica el valor semilla que determina la secuencia de valores que devuelve RAND( ). RAND( ) devuelve la misma secuencia de números aleatorios si utiliza el mismo valor semilla para nValorSemilla la primera vez que ejecuta la función RAND( ) seguida de llamadas posteriores a la función RAND( ) sin nValorSemilla. Si nValorSemilla es negativo la primera vez que ejecuta RAND( ), se usará un valor semilla a partir del reloj del sistema. Para obtener la serie más aleatoria de números, utilice inicialmente RAND( ) con un argumento negativo y, después, ejecute RAND( ) sin ningún argumento. Si omite nValorSemilla, RAND( ) utilizará de forma predeterminada el valor semilla 100.001. Microsoft® JScript™ Método random Referencia del lenguaje Versión 1 Vea también Se aplica a --------------------------------------------------------------------------------- Descripción Devuelve un número pseudoaleatorio entre 0 y 1. Sintaxis Math.random( ) Comentarios El número pseudoaleatorio generado es un número entre 0 y 1 ambos incluidos. El generador de números aleatorios se inicia automáticamente cuando se carga JScript por primera vez. rand Generates a pseudorandom number. int rand( void ); Routine Required Header Compatibility rand ANSI, Win 95, Win NT For additional compatibility information, see Compatibility in the Introduction. Libraries LIBC.LIB Single thread static library, retail version LIBCMT.LIB Multithread static library, retail version MSVCRT.LIB Import library for MSVCRT.DLL, retail version Return Value rand returns a pseudorandom number, as described above. There is no error return. Remarks The rand function returns a pseudorandom integer in the range 0 to RAND_MAX. Use the srand function to seed the pseudorandom-number generator before calling rand. Example /* RAND.C: This program seeds the random-number generator * with the time, then displays 10 random integers. */ #include #include #include void main( void ) { int i; /* Seed the random-number generator with current time so that * the numbers will be different every time we run. */ srand( (unsigned)time( NULL ) ); /* Display 10 numbers. */ for( i = 0; i < 10;i++ ) printf( " %6d\n", rand() ); } Output 6929 8026 21987 30734 20587 6699 22034 25051 7988 10104 Floating-Point Support Routines See Also srand srand Sets a random starting point. void srand( unsigned int seed ); Routine Required Header Compatibility srand ANSI, Win 95, Win NT For additional compatibility information, see Compatibility in the Introduction. Libraries LIBC.LIB Single thread static library, retail version LIBCMT.LIB Multithread static library, retail version MSVCRT.LIB Import library for MSVCRT.DLL, retail version Return Value None Parameter seed Seed for random-number generation Remarks The srand function sets the starting point for generating a series of pseudorandom integers. To reinitialize the generator, use 1 as the seed argument. Any other value for seed sets the generator to a random starting point. rand retrieves the pseudorandom numbers that are generated. Calling rand before any call to srand generates the same sequence as calling srand with seed passed as 1. Example /* RAND.C: This program seeds the random-number generator * with the time, then displays 10 random integers. */ #include #include #include void main( void ) { int i; /* Seed the random-number generator with current time so that * the numbers will be different every time we run. */ srand( (unsigned)time( NULL ) ); /* Display 10 numbers. */ for( i = 0; i < 10;i++ ) printf( " %6d\n", rand() ); } Output 6929 8026 21987 30734 20587 6699 22034 25051 7988 10104 Floating-Point Support Routine See Also rand