Zufällige Zahl ausgeben ?
Hi
Ich brauche ein Script/Befehl das/der eine Zufällige Zahl von 0-xxx (xxx=irgendeine Zahl) ausgibt.
Dabei muss noch beachtet werden,dass es 49,5% chance für gerade und ungerade zahl gibt und 1% für weitere Zahlen wie z.B. die 0.
Ich hoffe mal ihr versteht was ich meine.Ich weiß leider nicht wie es geht,da ich mich noch nie soviel mit rechnen/zahlen in Php auseinandergesetzt habe.
Mfg
Krueschta
Ich brauche ein Script/Befehl das/der eine Zufällige Zahl von 0-xxx (xxx=irgendeine Zahl) ausgibt.
Dabei muss noch beachtet werden,dass es 49,5% chance für gerade und ungerade zahl gibt und 1% für weitere Zahlen wie z.B. die 0.
Ich hoffe mal ihr versteht was ich meine.Ich weiß leider nicht wie es geht,da ich mich noch nie soviel mit rechnen/zahlen in Php auseinandergesetzt habe.
Mfg
Krueschta
Die Chance ist dabei aber nicht gewährleistet.
bzw 0 wird es nur dann mit 1% chance wenn es 100 zahlen sind (mit der 0 ) [theoretisch]
Wie man das macht, kann ich dir leider nicht ebantworten.
mfg Gimli
bzw 0 wird es nur dann mit 1% chance wenn es 100 zahlen sind (mit der 0 ) [theoretisch]
Wie man das macht, kann ich dir leider nicht ebantworten.
mfg Gimli
"Linux is evolution, not intelligent design." - Linus Torvalds
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »Gimli« (5. Mai 2004, 20:12)
Um es ziemlich genau zu sagen es ist bei folgendem Skript, das 10000000 mal ein zufällige Zahl ermittelt von 0 -100 folgendes herausgekommen:
Skript
Folgendes Ergebnis:
also alles fast 1 %, liegt aber auch daran, das es 101 Zahlen sind und net 100-
Skript
|
|
PHP-Quelltext |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
<?php
$max = 100; //Maximaler Zahlenwert
$min = 0; //Minimaler Zahlenwert
$zahl = 1;
while($zahl < 10000000)
{
$test = rand($min,$max);
$ausgabe[$test]++;
$zahl++;
}
$zahl2 = $min;
while($zahl2 <= $max)
{
echo "<br>Zahl: ".$zahl2." Hits: ".$ausgabe[$zahl2]." Prozent: ".$ausgabe[$zahl2]/100000;
$zahl2++;
}
?>
|
Folgendes Ergebnis:
|
|
Quellcode |
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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
Zahl: 0 Hits: 99475 Prozent: 0.99475 Zahl: 1 Hits: 98587 Prozent: 0.98587 Zahl: 2 Hits: 98718 Prozent: 0.98718 Zahl: 3 Hits: 98821 Prozent: 0.98821 Zahl: 4 Hits: 99619 Prozent: 0.99619 Zahl: 5 Hits: 98597 Prozent: 0.98597 Zahl: 6 Hits: 99228 Prozent: 0.99228 Zahl: 7 Hits: 98744 Prozent: 0.98744 Zahl: 8 Hits: 98746 Prozent: 0.98746 Zahl: 9 Hits: 99288 Prozent: 0.99288 Zahl: 10 Hits: 98539 Prozent: 0.98539 Zahl: 11 Hits: 98838 Prozent: 0.98838 Zahl: 12 Hits: 98760 Prozent: 0.9876 Zahl: 13 Hits: 98820 Prozent: 0.9882 Zahl: 14 Hits: 99080 Prozent: 0.9908 Zahl: 15 Hits: 99081 Prozent: 0.99081 Zahl: 16 Hits: 99459 Prozent: 0.99459 Zahl: 17 Hits: 98871 Prozent: 0.98871 Zahl: 18 Hits: 98965 Prozent: 0.98965 Zahl: 19 Hits: 98893 Prozent: 0.98893 Zahl: 20 Hits: 99152 Prozent: 0.99152 Zahl: 21 Hits: 98246 Prozent: 0.98246 Zahl: 22 Hits: 99074 Prozent: 0.99074 Zahl: 23 Hits: 99052 Prozent: 0.99052 Zahl: 24 Hits: 99561 Prozent: 0.99561 Zahl: 25 Hits: 99622 Prozent: 0.99622 Zahl: 26 Hits: 99184 Prozent: 0.99184 Zahl: 27 Hits: 99304 Prozent: 0.99304 Zahl: 28 Hits: 99307 Prozent: 0.99307 Zahl: 29 Hits: 99852 Prozent: 0.99852 Zahl: 30 Hits: 98678 Prozent: 0.98678 Zahl: 31 Hits: 98590 Prozent: 0.9859 Zahl: 32 Hits: 98783 Prozent: 0.98783 Zahl: 33 Hits: 99142 Prozent: 0.99142 Zahl: 34 Hits: 99360 Prozent: 0.9936 Zahl: 35 Hits: 98508 Prozent: 0.98508 Zahl: 36 Hits: 99638 Prozent: 0.99638 Zahl: 37 Hits: 98798 Prozent: 0.98798 Zahl: 38 Hits: 98855 Prozent: 0.98855 Zahl: 39 Hits: 99222 Prozent: 0.99222 Zahl: 40 Hits: 98710 Prozent: 0.9871 Zahl: 41 Hits: 99380 Prozent: 0.9938 Zahl: 42 Hits: 98875 Prozent: 0.98875 Zahl: 43 Hits: 99221 Prozent: 0.99221 Zahl: 44 Hits: 98947 Prozent: 0.98947 Zahl: 45 Hits: 98874 Prozent: 0.98874 Zahl: 46 Hits: 98859 Prozent: 0.98859 Zahl: 47 Hits: 98732 Prozent: 0.98732 Zahl: 48 Hits: 99310 Prozent: 0.9931 Zahl: 49 Hits: 98560 Prozent: 0.9856 Zahl: 50 Hits: 99552 Prozent: 0.99552 Zahl: 51 Hits: 98933 Prozent: 0.98933 Zahl: 52 Hits: 98665 Prozent: 0.98665 Zahl: 53 Hits: 98227 Prozent: 0.98227 Zahl: 54 Hits: 98490 Prozent: 0.9849 Zahl: 55 Hits: 99188 Prozent: 0.99188 Zahl: 56 Hits: 98998 Prozent: 0.98998 Zahl: 57 Hits: 99247 Prozent: 0.99247 Zahl: 58 Hits: 99209 Prozent: 0.99209 Zahl: 59 Hits: 99267 Prozent: 0.99267 Zahl: 60 Hits: 98996 Prozent: 0.98996 Zahl: 61 Hits: 98838 Prozent: 0.98838 Zahl: 62 Hits: 98994 Prozent: 0.98994 Zahl: 63 Hits: 98992 Prozent: 0.98992 Zahl: 64 Hits: 99306 Prozent: 0.99306 Zahl: 65 Hits: 98041 Prozent: 0.98041 Zahl: 66 Hits: 99491 Prozent: 0.99491 Zahl: 67 Hits: 99293 Prozent: 0.99293 Zahl: 68 Hits: 99111 Prozent: 0.99111 Zahl: 69 Hits: 98645 Prozent: 0.98645 Zahl: 70 Hits: 99293 Prozent: 0.99293 Zahl: 71 Hits: 99122 Prozent: 0.99122 Zahl: 72 Hits: 99130 Prozent: 0.9913 Zahl: 73 Hits: 99248 Prozent: 0.99248 Zahl: 74 Hits: 98635 Prozent: 0.98635 Zahl: 75 Hits: 99110 Prozent: 0.9911 Zahl: 76 Hits: 99079 Prozent: 0.99079 Zahl: 77 Hits: 99404 Prozent: 0.99404 Zahl: 78 Hits: 99659 Prozent: 0.99659 Zahl: 79 Hits: 99000 Prozent: 0.99 Zahl: 80 Hits: 99143 Prozent: 0.99143 Zahl: 81 Hits: 99070 Prozent: 0.9907 Zahl: 82 Hits: 99168 Prozent: 0.99168 Zahl: 83 Hits: 98268 Prozent: 0.98268 Zahl: 84 Hits: 98853 Prozent: 0.98853 Zahl: 85 Hits: 98931 Prozent: 0.98931 Zahl: 86 Hits: 98647 Prozent: 0.98647 Zahl: 87 Hits: 99049 Prozent: 0.99049 Zahl: 88 Hits: 99583 Prozent: 0.99583 Zahl: 89 Hits: 99144 Prozent: 0.99144 Zahl: 90 Hits: 98488 Prozent: 0.98488 Zahl: 91 Hits: 99344 Prozent: 0.99344 Zahl: 92 Hits: 99116 Prozent: 0.99116 Zahl: 93 Hits: 98949 Prozent: 0.98949 Zahl: 94 Hits: 99605 Prozent: 0.99605 Zahl: 95 Hits: 98773 Prozent: 0.98773 Zahl: 96 Hits: 98743 Prozent: 0.98743 Zahl: 97 Hits: 98671 Prozent: 0.98671 Zahl: 98 Hits: 99171 Prozent: 0.99171 Zahl: 99 Hits: 98948 Prozent: 0.98948 Zahl: 100 Hits: 98647 Prozent: 0.98647 |
also alles fast 1 %, liegt aber auch daran, das es 101 Zahlen sind und net 100-
Ähnliche Themen
-
(X)HTML & CSS & DHTML & Javascript »-
erstaunlich
(23. Mai 2007, 05:27)
-
PHP »-
Hilfe: Werte durch ":" trennen ..
(19. Juni 2006, 20:38)
-
PHP »-
Zahl mit Nullen auffüllen
(18. Mai 2006, 15:41)
-
PHP »-
Zahlen von 1- 999 ausgeben !!
(13. April 2003, 14:20)
-
PHP »-
immer abrunden
(4. Januar 2003, 19:28)


