sAks: Zufallstext

Beitrag lesen

Vielen Dank Ihnen beiden. Vorallem der Link hat mich, zusammen mit einer weiteren Recherche, auf zwei Ideen gebracht:

  
var msg = new Array();  
msg[1] = "Tip 1";  
[...]  
  
  
a = Math.random();  
function getRandom( max )  
{  
iRandom = Math.round((Math.random() * max + 0.5));  
return iRandom;  
}  
rnd = getRandom(60);  
  
  
function tip() {  
document.write(msg[rnd]);  
}  

_und_______________________________

  
var msg = new Array();  
msg[1] = "Tip 1";  
[...]  
  
      function GetRandom( min, max ) {  
              if( min > max ) {  
                      return( -1 );  
              }  
              if( min == max ) {  
                      return( min );  
              }  
  
              return( min + parseInt( Math.random() * ( max-min+1 ) ) );  
      }  
function tip() {  
document.write(msg[GetRandom(1,60)]);  
}  
  

Kann man sagen, dass eine Version davon sicherer/eleganter ist?

P.S. Bei dem ersten Rechensystem ist ja die Zahl _0_ durch dieses " + 0.5" und math.round mathematisch gesehen nicht inbegriffen?!