Ver Mensaje Individual
  #81 (permalink)  
Antiguo 20/03/2004, 10:38
Avatar de meru-kun
meru-kun
 
Fecha de Ingreso: noviembre-2002
Ubicación: Madrid
Mensajes: 854
Antigüedad: 21 años, 5 meses
Puntos: 0
Sacar una serie de n números aleatorios, distintos entre sí dentro de un rango de valores.

Primero, las funciones a utilizar, que son tres:
Código:
'####################
'# Funciónes creadas por Isaí/Meruelo
'# Optimizadas por meruelo
'####################

Function RanNum(inicio, fin)
 Randomize()
  RanNum = Int((fin - inicio + 1) * Rnd + inicio)
End Function

Function chkRan(num, pos)
p = val_inicial
 Do while p <= val_final
  For d=0 To d=9
   If arreglo(d)=num then
     arreglo(pos) = RanNum(val_inicial, val_final)
      p = 1
   Else
     chkRan = num
      p = p + 1
   End if
  Next
 Loop
End Function

Function getArray(val_inicial, val_final)
indice_elem_actual=0
Do While indice_elem_actual<=numero_elementos
	numero=RanNum(val_inicial,val_final)
	For j=0 To (numero_elementos)
		If arreglo(j)=numero Then
			numero=RanNum(val_inicial,val_final)
			j=0
		End If
	Next
	arreglo(indice_elem_actual)=chkRan(numero, pos)
	indice_elem_actual=indice_elem_actual+1
Loop
End Function
Despues, simplemente, definir el arreglo
Código:
Dim arreglo()
Y, como ejemplo, crear un bucle para mostrar todos los números que saca

Código:
 i = 0
   numero_elementos= 4
	Redim arreglo(numero_elementos)
	      call getArray(1, numero_límite)
	          Do While i < numero_elementos
                              response.write arreglo(i)
                                  i = i + 1
                          Loop
__________________
Tu portal de manga y anime.