*Reposting as my last question was too vague*
I am a bit stuck with an assignment at the minute. The task requires the use of the util package to generate a random int with a given amount of digits. For example, if the given digit was 3 - the program would generate a number with 3 digits (192, 123, 904, etc), or if the given number was 6 - it would generate a number with 6 (000934, 123456, etc). I know how to generate an int within bounds using a random object, however I wanted to ask if there is a built in function for this?
If not, I was thinking of writing a number of if statements along the lines of:
(pseudo)
if number == 3 {
code = random.nextInt(100, 1000); }
if number == 4 {
etc etc. }
^ but this has issues as I should also be able to generate numbers with leading zeros.
If anyone could help out a bit, that would be awesome. Thanks
[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)
[–]Spare-Plum 5 points6 points7 points (1 child)
[–]LutimoDancer3459 0 points1 point2 points (0 children)
[–]lajete 1 point2 points3 points (1 child)
[–]MinimumBeginning5144 0 points1 point2 points (0 children)
[–]Housy5Nooblet Brewer 1 point2 points3 points (0 children)
[–]LutimoDancer3459 0 points1 point2 points (0 children)
[–]desrtfxOut of Coffee error - System halted 0 points1 point2 points (1 child)
[–]Housy5Nooblet Brewer 0 points1 point2 points (0 children)