Cliccando qui: prob.htm   avvi uno script che ti permette di studiare sperimentalmente la probabilità di un evento. La modellizzazione dell'evento è da scrivere nella function ValVer. Sotto puoi accedere a una visualizzazione codice del file, che, nella versione originale, è predisposto per lo studio dell'uscita 7 nel lancio di due dadi equi. Sotto sono esemplificati alcuni modi in cui modificare ValVer.
Puoi modificare Prob.htm (attivalo ed esaminane il codice sorgente) oppure puoi copiare il codice a cui accedi cliccando qui sotto, salvarlo in un file con un nuovo nome e modificare ValVer.

codice

esce 7 lanciando 2 dadi equi  
function ValVer()
{ with(Math) {
// -------
U1 = floor(random()*6+1);
U2 = floor(random()*6+1);
if (U1+U2==7)
{ V = 1 }
else
{ V = 0 }
// -------
}}
 
tris di mano (ossia tra 10 carte estratte da mazzo di 40)
function ValVer()
{ with(Math) {
// -------
var c = new Array(); var n = new Array();
tris=0;
// azzero c[] in cui marco le carte uscite
for (seme=1; seme < 5; seme++)
  {for (valore=1; valore < 11; valore++)
    {c[10*(seme-1)+valore]=0; n[valore]=0} }
// genero 10 carte
for (carta=0; carta < 10; carta++)
  {ripeti=1;
  while (ripeti==1)
    {seme=floor(random()*4+1);
    valore = floor(random()*10+1);
    if (c[10*(seme-1)+valore]==0) { ripeti = 0}}
  c[10*(seme-1)+valore]=1; n[valore]=n[valore]+1}
// guardo se ci sono tris
for (var valore=1; valore < 11; valore++)
  {if (n[valore]==3 || n[valore]==4) {tris=1}}
if (tris==1) {V = 1} else {V = 0}
// -------
}}

JavaScript supports the following mathematical functions (methods of the Math object):

Math.abs(a)     // the absolute value of a
Math.acos(a)    // arc cosine of a
Math.asin(a)    // arc sine of a
Math.atan(a)    // arc tangent of a
Math.atan2(a,b) // arc tangent of a/b
Math.ceil(a)    // integer closest to a and not less than a
Math.cos(a)     // cosine of a
Math.exp(a)     // exponential of a
Math.floor(a)   // integer closest to and not greater than a
Math.log(a)     // log of a base e
Math.max(a,b)   // the maximum of a and b
Math.min(a,b)   // the minimum of a and b
Math.pow(a,b)   // a to the power b
Math.random()   // pseudorandom number in the range 0 to 1
Math.round(a)   // integer closest to a 
Math.sin(a)     // sine of a
Math.sqrt(a)    // square root of a
Math.tan(a)     // tangent of a