Visual Basic Foro

Programación => Visual Basic 6 => Mensaje iniciado por: Bazooka en Octubre 11, 2012, 03:04:34 pm

Título: Manipular Randomize es posible.
Publicado por: Bazooka en Octubre 11, 2012, 03:04:34 pm
Hola tengo una función  como la que poste abajo que me devuelve una cadena de 7 numeros aleatorios y utiliza un parametro para determinar si utilizo o no randomize.

Ahora si le paso a la funcion cero ( GENERA(7, 0))
Caption = GENERA(7, 0)  'GENERA SIEMPRE LA PRIMERA VEZ ESTO 36 27 29 15 16 39 1

Ahora si le paso a la funcion UN NUMERO POR EJEMPLO ( GENERA(7, 150))
Caption = GENERA(7, 150)  'GENERA SIEMPRE LA PRIMERA VEZ ESTO  15 35 21 48 43 29 22

MI CONSULTA ES LA SIGUIENTE:
HAY UN MODO QUE SI YO LA LLAMO POR EJEMPLO 3 VECES CON LOS MISMOS PARAMETROS ME DEVUELVA SIEMPRE LA MISMA COMBINACION DE NUMEROS?

Caption = GENERA(7, 150)  ME DEVUELVA LA 1º VEZ 15 35 21 48 43 29 22
Caption = GENERA(7, 150)  ME DEVUELVA LA 2º VEZ 15 35 21 48 43 29 22
Caption = GENERA(7, 150)  ME DEVUELVA LA 3º VEZ 15 35 21 48 43 29 22


'GENERA LA CANTIDAD DE NUMEROS PASADO COMO PARAMETROS Y LOS DEVUELVE EN UN FORMATO ASI
'"20 41 22 3 24 15 36"
Código: [Seleccionar]
Private Function GENERA(num As Byte, SEMILLA As Long) As String
Dim i As Byte
Dim T As String

If SEMILLA > 0 Then Randomize SEMILLA

For i = 1 To num
    T = T & " " & GetRandomNumber
Next
GENERA = T
End Function

Private Sub Command2_Click()
 Caption = GENERA(7, 0)  'GENERA LA PRIMERA VEZ  36 27 29 15 16 39 1
'Caption = GENERA(7, 150) 'GENERA LA PRIMERA VEZ  15 35 21 48 43 29 22
Debug.Print Caption
End Sub

Private Function GetRandomNumber() As Byte

    GetRandomNumber = Int((50) * Rnd + (1))
   
End Function
Título: Re:Manipular Randomize es posible.
Publicado por: cobein en Octubre 11, 2012, 07:21:22 pm
para obtener la misma secuencia tenesque reiniciar el generador, eso lo haces usando rnd(-1)
Título: Re:Manipular Randomize es posible.
Publicado por: Bazooka en Octubre 11, 2012, 08:02:03 pm
buenisimo!! no sabia!
gracias
Título: Re:Manipular Randomize es posible.
Publicado por: LeandroA en Octubre 11, 2012, 09:51:25 pm
buenisimo!! no sabia!
gracias

idem
Título: Re:Manipular Randomize es posible.
Publicado por: YAcosta en Octubre 11, 2012, 11:50:17 pm
Bien alli Cobein, como siempre sorprendiendo.