# Fixed length for random number generation

Hihi

I need to create a 4 digit random number, however when I used new random().Next(0000,9999) this also generated results such as 123/ 25. I need it to start with 0123 or 0025 - to get 4 digits. Any idea how to do this? I tried formatvalue but that does not seem right.

Thank you!

Have another variable make it constant with what number you need then Concatenate it with actual generated

var Const = 0123

and new random().Next(00,99)

Thanks,
Prankur

Hi @donutlearns,

Your question seems to be interesting, i have tried this and got the result.

The one thing i did was i have generated random number from 0000-9999 and took the resulted value concatenated with β0000β to the left.

and finally i used substring and took last 4 digit number.

I think this is what you were looking at.

Summerized:

Random number-23
concatenate string-0000

Result=000023

Final result=0023

Thank You

Regards,
Kanthesh

P.S- If you require a solution workbook please ping me.

Hello,

I have attached a working solution.

.Random.xaml (6.0 KB)

1 Like

Thanks @kantheshm

I did not think of it this way! Nice.

Thanks @Anusha_Makam

This is exactly right! Awesome!

I think @Anusha_Makam has tried my logic and got right,
Appreciate it.

Hi @donutlearns,

Mark your question as answered with a solution marked,so that others can find solution and try that out.

Regards,
Kanthesh

hi
i am using random function {"new random().next(1,100) " } ,but itβs generated duplicate numbers ? please help me

my requirement is " excel file column A is their 100 values " so robot take the random value from column A ?

Hi,

Padleft should be able to help.