Random number generator for a given length

moonbeam

New Member
Joined
Feb 8, 2012
Messages
9
I need to generate random numbers on certain length that is input by the user.

For eg.
If the user inputs the value 5, a random number of 5 digits should be generated

and user can input any value between 1 and 30 and a number with that many digits should be generated.

I searched quite a bit before posting this, but could not find any posts that could help me
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
there may be a better way but you get the idea here

Sheet1

A
B
C
D
3
2
93

<tbody>
</tbody>

Spreadsheet Formulas

Cell
Formula
D3
=IF(A3=1,RANDBETWEEN(0,9),IF(A3=2,RANDBETWEEN(10,99),IF(A3=3,RANDBETWEEN(100,999),IF(A3=4,RANDBETWEEN(1000,9999),IF(A3=5,RANDBETWEEN(10000,99999))))))

Randbetween not available in 2003

<tbody>
</tbody>

<tbody>
</tbody>


Excel tables to the web >> Excel Jeanie HTML 4
 
Upvote 0
Sorry, I never saw that you wanted to out to 30 digits, this will not go that far out.
 
Upvote 0
= LEFT(RANDBETWEEN(1,9)
& RANDBETWEEN(0,999999999999999)
& RANDBETWEEN(0,999999999999999), A1)


The results is a text string (numbers in Excel can only have 15 significant digits)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,146
Messages
6,129,142
Members
449,488
Latest member
qh017

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top