Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> generowanie liczb
right6
post
Post #1





Grupa: Zablokowani
Postów: 206
Pomógł: 0
Dołączył: 9.03.2006

Ostrzeżenie: (0%)
-----


mam problem jak w js, wygenerowac, w petli, iles tam liczb od 1-20, ale zeby byly rozlozone losowo, i kazda z nich wystepowala dwa razy.
wiec bedziemy miec w sumie 40 liczb.
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
right6
post
Post #2





Grupa: Zablokowani
Postów: 206
Pomógł: 0
Dołączył: 9.03.2006

Ostrzeżenie: (0%)
-----


albo zle cos robie, albo cos niedziala (IMG:http://forum.php.pl/style_emoticons/default/dry.gif)

Kod
<html>
      <head>
          <script language="JavaScript" type="text/javascript">

function rand(intStart, intEnd) {
  return intStart + Math.floor(Math.random() * (intEnd - intStart));
}

function right6Generator(intStart, intEnd)
{
  var arrNumbers = new Array();
  var i = 0;
  while (intStart <= intEnd)
  {
      arrNumbers[i++] = intStart;
      arrNumbers[i++] = intStart++;
  }

  var arrResult = new Array();
  for (i = arrNumbers.length - 1; i >= 0; i--)
  {
      intIndex = rand(0, i + 1);
      arrResult[i] = arrNumbers.splice(intIndex, 1);
  }

  return arrResult;
}
</script>
      </head>

<body>

<div onclick="right6Generator(1, 20)">aaaa</div>

</body>

</html>
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 7.10.2025 - 10:29