jeudi 16 avril 2020

Generating random unidentical numbers from 100-9999 [duplicate]

How do I generate a random distinct 3 or 4 digit number in Java, without using , arrays, loops or methods( except the in-built math random method for generating random numbers) , just the basic things like if-statements.

I tried using

(int)(Math.random()*9899+100);

But it's only returning 4 digit indistinct numbers. By distinct I mean, no number should repeat itself. Numbers like 252, 7277, 889, 191 aren't allowed. But numbers like 1234, 3456, 8976, 435 are distinct, unidentical and allowed

Aucun commentaire:

Enregistrer un commentaire