Bessere Zufallszahlen

danke fuer die schnelle antwort !

aber das ist mir grad nich tganz klar. du addierst zu der zufallszhal im integerbereich 1 und multiplizierst mit 100 ? ist die zahl dann nicht nich größer ?
 
Ist selbsterklärend.

double zz=(Math.random()); == z.B. 0.6687084221565738

double zz=(1+Math.random()); == z.B. 1.9123989183256658

double zz=(1+Math.random()*100); == z.B. 68.9651708563168

double zz=(int)(1+Math.random()*100); == z.B. 17.0

int zz=(int)(1+Math.random()*100); == z.B. 29

P.S.: So viel Mühe für nichts. Tut mir leid.
 
Zuletzt bearbeitet:
Hallo,

schau mal hier:
Java:
/**
 * 
 */
package de.tutorials;

import java.util.Random;

/**
 * @author Thomas.Darimont
 * 
 */
public class RandomUtil {

    final static Random RANDOMIZER = new Random();

    public static double randomValueBetween(double lowerBound, double upperBound) {
        return lowerBound + (upperBound - lowerBound) * RANDOMIZER.nextDouble();
    }

    public static int randomValueBetween(int minInclusive, int maxExclusive) {
        return minInclusive + RANDOMIZER.nextInt(maxExclusive - minInclusive);
    }

    public static void main(String[] args) {
        for (int i = 0; i < 100000; i++) {
            System.out.println(randomValueBetween(1, 100));
        }
    }
}

Gruß Tom
 
danke fuer eure hilfen :) !

habs gemacht wie stigma geschrieben hat, geht einwandfrei danke :) !

hier mein code:
PHP:
        public int eineZufallszahlAusgeben()    
        {         
            int result=(int)(1+Math.random()*100);
            return result;
        }

  public void main(int wert1, int wert2)
  {
    int[][] array = new int[wert1][wert2];
        int i=0,j=0;
        
    for(i=0; i<wert1; i++)
    { 
        for(j=0; j<wert2; j++)  
        {
            int zufall = eineZufallszahlAusgeben();
            array[i][j] = zufall;   
            System.out.println("i="+i+"j="+j+" =  "+zufall);
        }
    }
 
Zuletzt bearbeitet:
@ yeronimo:
Schön das ich dir helfen konnte! Der Code von Tom ist aber auch nicht schlecht. Dafür bedank ich mich.
 
Zuletzt bearbeitet:
Zurück