Foros del Web » Programando para Internet » Javascript »

Como crear este simple Script ?

Estas en el tema de Como crear este simple Script ? en el foro de Javascript en Foros del Web. Estoy buscando cientos de sitios pero no logro saber como crear un script el cual te muestre 6 números del 1 al 49 al azar, ...
  #1 (permalink)  
Antiguo 23/04/2013, 00:53
 
Fecha de Ingreso: febrero-2013
Mensajes: 264
Antigüedad: 11 años, 2 meses
Puntos: 1
Como crear este simple Script ?

Estoy buscando cientos de sitios pero no logro saber como crear un script el cual te muestre 6 números del 1 al 49 al azar, pero que no los repita, esto se puede hacer ? gracias
  #2 (permalink)  
Antiguo 23/04/2013, 01:07
Avatar de David
Moderador
 
Fecha de Ingreso: abril-2005
Ubicación: In this planet
Mensajes: 15.720
Antigüedad: 19 años
Puntos: 839
Respuesta: Como crear este simple Script ?

Podría ser:
Código Javascript:
Ver original
  1. var numeros = [];
  2. var aleatorios = [];
  3. for (var i = 0; i < 49; i++) {
  4.     numeros[i] = i + 1;
  5. }
  6. for (var i = 0; i < 6; i++)
  7. {
  8.     var aleatorio = Math.floor(Math.random() * numeros.length);
  9.     aleatorios[aleatorios.length] = numeros[aleatorio];
  10.     numeros.splice(aleatorio, 1);
  11. }
  12. alert(aleatorios);
__________________
Por favor, antes de preguntar, revisa la Guía para realizar preguntas.
  #3 (permalink)  
Antiguo 23/04/2013, 18:29
 
Fecha de Ingreso: febrero-2013
Mensajes: 264
Antigüedad: 11 años, 2 meses
Puntos: 1
Respuesta: Como crear este simple Script ?

Gracias David. Aunque casi lo tengo de otra web, sin embargo le falta un detalle que considero muy importante,ya que sino no tiene gracia, y esque cuando muestra un numero me gustaria que dejara aunque sea 1 segundo de tiempo entre mostrar un numero y otro, ahora mismo muestra los 6 al instante y eso para la presentacion es muy malo, solo me falta eso, alguien lo sabe ?, aqui pego el codigo :


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>suer</title>
<script type="text/javascript" language="javascript">
var lotto = {
max : 49,
num : 6,
stars: 0
}

function lottery() {
printNumbers(getNumbers((lotto.num+lotto.stars),lo tto.max),"lotto");
}
function printNumbers(numbers,type){
for(var x in numbers){
document.getElementById(type+x).innerHTML = numbers[x];
}
}
function getNumbers(totalBalls,balls) {
var numbers = [];
for (var i = balls; i > 0; i--){
numbers.push(i);
}
numbers.sort(
function(){
return (Math.round(Math.random())-0.5);
}
);
return numbers.slice(0,totalBalls);
}
</script>
</head>
<body background="wide.jpg" text="#000000">
<div align="left">&nbsp;&nbsp;
<table width="815" border="0" cellspacing="0" cellpadding="0" bordercolor="#990066" height="142">
<tr>
<td width="100" align="center" id="lotto0" height="73" background="ro.png"><b><i></i></b></td>
<td width="100" align="center" id="lotto1" height="73" background="vr.png"><b><i></i></b></td>
<td width="100" align="center" id="lotto2" height="73" background="poj.png"><b><i></i></b></td>
<td width="100" align="center" id="lotto3" height="73" background="rppos.png"><b><i></i></b></td>
<td width="100" align="center" id="lotto4" height="73" background="a.png"><b><i></i></b></td>
<td width="100" align="center" id="lotto5" height="73" background="lzu.png"><b><i></i></b></td>
</tr>
</table>
</div>
<p align="left"><font size="7"><b>
<input type="button" value="MOSTRAR" id="reload" onClick="lottery()" name="button">
</b></font></p>
<p align="left">&nbsp;</p>
<p>&nbsp;</p>
</body>
</html>

Última edición por soloandroid; 23/04/2013 a las 22:03

Etiquetas: simple
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 04:04.