Toon posts:

Probleem met random functie (mt_rand)

Pagina: 1
Acties:

Verwijderd

Topicstarter
<?php

function make_seed()
{
return (double)microtime()*1000000;
}
mt_srand(make_seed());

while ($count < 10000)
{
$randomize = $randomize + mt_rand(1,10);
$count = $count + 1;
}

print $randomize;
print("<br>");




while ($count < 10000)
{
$randomize = $randomize + mt_rand(1,10);
$count = $count + 1;
}

print $randomize;

print("<br>");



while ($count < 10000)
{
$randomize = $randomize + mt_rand(1,10);
$count = $count + 1;
}

print $randomize;
?>


check een werkend voorbeeld op http://www.needforgaming.com/test.php


Waarom doet ie NIKS bij de 2e en 3e loop?

Ik wil dat ie weer nieuwe randomwaardes gaat maken.. maar hoe doe ik dat?

  • Glimi
  • Registratie: Augustus 2000
  • Niet online

Glimi

Designer Drugs

(overleden)
Zet de seed opniew...dus opnieuw mt_srand();

[edit]voor je uitgewerkt :)
PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?
 
function make_seed() 
{ 
return (double)microtime()*1000000; 
} 
mt_srand(make_seed()); 

while ($count < 10000) 
{ 
$randomize = $randomize + mt_rand(1,10); 
$count = $count + 1; 
} 

print $randomize; 
print("<br>"); 

/* 
Zet de seed opnieuw om de basis van de randomizer te veranderen
*/
mt_srand(make_seed()); 
while ($count < 10000) 
{ 
$randomize = $randomize + mt_rand(1,10); 
$count = $count + 1; 
} 

print $randomize; 

print("<br>"); 

/* 
Zet de seed opnieuw om de basis van de randomizer te veranderen
*/
mt_srand(make_seed()); 
while ($count < 10000) 
{ 
$randomize = $randomize + mt_rand(1,10); 
$count = $count + 1; 
} 

print $randomize; 
?>