Autor Tema: Manipular Randomize es posible.  (Leído 3256 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Bazooka

  • Terabyte
  • *****
  • Mensajes: 951
  • Reputación: +31/-20
  • El pibe Bazooka
    • Ver Perfil
    • Desof sistemas
Manipular Randomize es posible.
« 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
Todos somos muy ignorantes. Lo que ocurre es que no todos ignoramos las mismas cosas.

cobein

  • Moderador Global
  • Gigabyte
  • *****
  • Mensajes: 348
  • Reputación: +63/-0
  • Más Argentino que el morcipan
    • Ver Perfil
Re:Manipular Randomize es posible.
« Respuesta #1 en: Octubre 11, 2012, 07:21:22 pm »
para obtener la misma secuencia tenesque reiniciar el generador, eso lo haces usando rnd(-1)

Bazooka

  • Terabyte
  • *****
  • Mensajes: 951
  • Reputación: +31/-20
  • El pibe Bazooka
    • Ver Perfil
    • Desof sistemas
Re:Manipular Randomize es posible.
« Respuesta #2 en: Octubre 11, 2012, 08:02:03 pm »
buenisimo!! no sabia!
gracias
Todos somos muy ignorantes. Lo que ocurre es que no todos ignoramos las mismas cosas.

LeandroA

  • Administrador
  • Petabyte
  • *****
  • Mensajes: 1128
  • Reputación: +151/-8
    • Ver Perfil
Re:Manipular Randomize es posible.
« Respuesta #3 en: Octubre 11, 2012, 09:51:25 pm »
buenisimo!! no sabia!
gracias

idem

YAcosta

  • Moderador Global
  • Exabyte
  • *****
  • Mensajes: 2853
  • Reputación: +160/-38
  • Daddy de Qüentas y QüeryFull
    • Ver Perfil
    • Personal
Re:Manipular Randomize es posible.
« Respuesta #4 en: Octubre 11, 2012, 11:50:17 pm »
Bien alli Cobein, como siempre sorprendiendo.
Me encuentras en YAcosta.com