Espacios de nombres
Variantes
Acciones

Diferencia entre revisiones de «cpp/numeric/random/srand»

De cppreference.com
< cpp‎ | numeric‎ | random
m (Texto reemplaza - '<code cpp>' a '<syntaxhighlight lang="cpp">')
m (Use {{lc}}. Update links. Various fixes.)
 
(No se muestran 7 ediciones intermedias realizadas por 3 usuarios)
Línea 1: Línea 1:
{{title|srand}}
+
{{
Sintaxis:
+
title|srand}}
 +
 +
 +
 +
  
<syntaxhighlight lang="cpp">
+
seed
    #include <cstdlib>
+
    void srand( unsigned seed );
+
</syntaxhighlight>
+
  
La función ''srand()'' establece la "semilla" o valor inicial utilizado por el generador ''[[cpp/numeric/random/rand | rand()]]''. Por cada valor posible de la semilla, el generador arrojará repetidamente un listado específico de valores "aleatorios".
+
 +
 +
el valor de la semilla
 +
  
<syntaxhighlight lang="cpp">
+
=
    srand( time(0) );
+
()()
    for( i = 0; i < 10; i++ )
+
      printf( "Random number #%d: %d\n", i, rand() );
+
</syntaxhighlight>
+
  
===Escogiendo Semillas===
+
======
Dado que la secuencia generada es siempre la misma para un valor fijo de la semilla, ''srand()'' debiera ser llamada con un argumento cambiante y que no dependa de la compilación. Ejemplos de semillas incluyen:
+
 +
 +
 +
  
**Usar el tiempo del reloj del sistema como es provisto por ''time'':**
+
=
<syntaxhighlight lang="cpp">
+
#include <ctime>
+
srand ( time (0) );
+
/
</syntaxhighlight>
+
  
**Usar el identificador de proceso en sistemas POSIX:**
+
de:cppsrand
<syntaxhighlight lang="cpp">
+
/
#include <unistd.h>
+
:cpp
srand ( getpid() );
+
:srand
</syntaxhighlight>
+
/
 
+
[[cpp/numeric/random/]]
**Si ya se ha recibido entrada de datos del usuario, usar alguna combinación de valores ingresados:**
+
[[cpp///
<syntaxhighlight lang="cpp">
+
:]]
#include <iostream>
+
int a, b;
+
std::cin>> a>> b;
+
srand ( a^b );
+
</syntaxhighlight>
+
 
+
 
+
===Tópicos Relacionados===
+
* ''[[cpp/numeric/random/rand | rand]]''
+
* [[cpp/c/other/..:date:time | time (Tiempo Estándar en C)]]
+

Última revisión de 00:10 2 jul 2013

 
 
 
Generación de números pseudoaleatorios
Motores y adaptadores de motor
Original:
Engines and engine adaptors
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Generadores
Original:
Generators
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Distribuciones
Original:
Distributions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Distribuciones uniformes
Original:
Uniform distributions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Bernoulli distribuciones
Original:
Bernoulli distributions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Poisson distribuciones
Original:
Poisson distributions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Distribuciones normales
Original:
Normal distributions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Distribuciones de muestreo
Original:
Sampling distributions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Secuencias de semillas
Original:
Seed Sequences
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
(C++11)
C biblioteca
Original:
C library
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
srand
 
Definido en el archivo de encabezado <cstdlib>
void srand( unsigned seed );
Inicializa el generador de números aleatorios para generar valores para rand() con el valor de inicialización seed .
Original:
Initializes the built-in random number generator used to generate values for rand() with the seed value seed.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Contenido

[editar] Parámetros

seed -
el valor de la semilla
Original:
the seed value
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[editar] Valor de retorno

(Ninguno)
Original:
(none)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[editar] Ejemplo

[editar] Ver también

Genera un número pseudoaleatorio.
(función) [editar]