Random Number Generator

FRED_SHEET

New Member
Joined
Oct 13, 2017
Messages
48
I am trying to use a Random Number Generator to test a worksheet I am developing. I have been using the expression shown below with success to generate a number between 1 and 63 to put in a cell.

=TRUNC(RAND()*(64-1)+1)

However, I would like to test this cell with a random number between 0 and 63 and a null entry or blank in the cell generated randomly. I tried using the expression below but it doesn't seem to give be a zero, maybe I have tried enough times.

=TRUNC(RAND()*(64-0)+1)

Also, is there anyway to generate a blank entry randomly along with random entries from 0 to 63?
[TABLE="width: 100"]
<colgroup><col></colgroup><tbody>[TR]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Hi ,

The RAND() function generates a random number between 0 and 1 , 0 inclusive , 1 exclusive.

When you have 0 being generated , multiplying the result by any number and then adding 1 will always give you 1 , never 0.

To generate a random number between 0 and 63 , just use :

=RANDBETWEEN(0,63)

Now , to generate a blank randomly , try using :

=RANDBETWEEN(0,64)

in one column , and in a second column , use a formula such as :

=IF(random number < 64 , random number , "")

So , as long as the random number generated is between 0 and 63 , the same will be reflected in the second column , but when the random number generated is 64 , the second column will contain a blank.
 
Upvote 0
Hi ,

The RAND() function generates a random number between 0 and 1 , 0 inclusive , 1 exclusive.

When you have 0 being generated , multiplying the result by any number and then adding 1 will always give you 1 , never 0.

To generate a random number between 0 and 63 , just use :

=RANDBETWEEN(0,63)

Now , to generate a blank randomly , try using :

=RANDBETWEEN(0,64)

in one column , and in a second column , use a formula such as :

=IF(random number < 64 , random number , "")

So , as long as the random number generated is between 0 and 63 , the same will be reflected in the second column , but when the random number generated is 64 , the second column will contain a blank.

THANK YOU - using this I was able to generate a cell with the random numbers I wanted and a blank.:)
 
Upvote 0
THANK YOU - using this I was able to generate a cell with the random numbers I wanted and a blank.:)
The formula wideboydixon posted in Message #5 will do what you want without needing to use two columns.

And here is another way to do it without using two columns...

=SUBSTITUTE(RANDBETWEEN(0,64),64,"")
 
Last edited:
Upvote 0
The formula wideboydixon posted in Message #5 will do what you want without needing to use two columns.

And here is another way to do it without using two columns...

=SUBSTITUTE(RANDBETWEEN(0,64),64,"")
Actually, in rereading your original post, I think you wanted your random numbers to go from 1 to 63 (plus a blank), not 0 to 63 (plus a blank) like the formula above does. If that is correct, then use this formula instead...

=SUBSTITUTE(RANDBETWEEN(0,63),0,"")

By the way, mikerickson has an interesting formula in Message #4 ... it allows you to set an approximate percentage of the time the blank should appear. As written, Mike's formula generates a blank about half of the time and the other half of the time a number between 1 and 63. If you wanted the blank to appear about one quarter of the time, you would change the 0.5 to 0.25. If you wanted the blank to appear about 1/64th of the time (making it a fairly generated random number), you would use either 1/64 or 0.015625 in place of the 0.5 he used.
 
Last edited:
Upvote 0
Rick the last formula will never return a result divisible by 10. The 0 gets blanked.

SUBSTITUTE(RANDBETWEEN(1, 64),64,"") will avoid that issue
 
Upvote 0
Rick the last formula will never return a result divisible by 10. The 0 gets blanked.

SUBSTITUTE(RANDBETWEEN(1, 64),64,"") will avoid that issue
Yes, you are correct... of course. :banghead:

I had tried to get cute and save a couple of characters without thinking about the consequences. Thanks for catching that.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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