dimanche 13 septembre 2015

Generating only odd numbers randomly

trying to generate odd numbers randomly I tried this, but it generates even nums also:

int coun=random.nextInt();
for(int i=1; i<100; i++){
    if(i%2==1){
      coun=random.nextInt(i);
    }
}

Any hint? how can generate odd nums randomly?




Aucun commentaire:

Enregistrer un commentaire