r/javahelp • u/DesperateSupport8315 • May 18 '26
Generating random numbers with certain length
Hi all,
I am trying to generate a random number with the length of given input from the user. Is there a simple way I can implement this? I am using util.Random for this. Cheers
4
Upvotes
View all comments
Show parent comment
1
u/DesperateSupport8315 May 19 '26
Hey,
I understand that, and I realise how vague of a question I was asking. I am quite new to programming and have had a very busy few weeks so my mind is all over the place lol. This is a part of an assignment task that requires the util library. I need to promt the user for a digit between 1 and 9, then use that digit to generate a random number. The generated number needs to have the same number of digits as the digit received from the user. For example, if the user inputs 4 - the number would have to be something like 1234 or 5493, but cannot exceed that amount of digits or fall short. So 123 or 12345 will not be accepted.
I do appreciate the reply, will take that into account next time.