Random Number Within Specific Range (Function)

dmrcs

New Member
Joined
Dec 5, 2021
Messages
14
Office Version
  1. 365
Hello there,

Seen a lot of literature on this but not something as specific (via organic search).

Let's say I have a list of numbers in one column. What function (no macro) would enable me to randomise the appearance of a number not in the first column but within a specific range (from 1 to 100).

Screenshot 2021-12-05 at 14.47.13.png


In other words, a function that would show a number in cell C2 not currently featured on list in column B, but that number has to be between 1 to 100.

I've seen functions that can show a random number currently featured, but no function that shows a number not currently there.

Could it also be made more complex? As in: "I want the random number to have at least a 6 in it" so you get 16, 26, 36...

Many thanks in advance!
 

dmrcs

New Member
Joined
Dec 5, 2021
Messages
14
Office Version
  1. 365
Hi & welcome to MrExcel.
How about
Excel Formula:
=LET(s,SEQUENCE(100),f,FILTER(s,(ISNA(MATCH(s,B2:B7,0)))*(ISNUMBER(FIND(6,s)))),INDEX(SORTBY(f,RANDARRAY(ROWS(f))),1))
@Fluff
Sorry to disturb, any chance this could be updated to avoid giving numbers with 6s in it?
The other formula just seems to fail when there's more than 100 rows (I've tried fiddling with it, there are over 1000 on the file, but it returns a REF error).
Many thanks!
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
77,510
Office Version
  1. 365
Platform
  1. Windows
How about
Excel Formula:
=LET(s,SEQUENCE(100),f,FILTER(s,ISNA(MATCH(s,B2:B7,0))),INDEX(SORTBY(f,RANDARRAY(ROWS(f))),1))
But if you have over 1000 values in col B, how do you expect to return a number between 1 & 100?
 

dmrcs

New Member
Joined
Dec 5, 2021
Messages
14
Office Version
  1. 365
How about
Excel Formula:
=LET(s,SEQUENCE(100),f,FILTER(s,ISNA(MATCH(s,B2:B7,0))),INDEX(SORTBY(f,RANDARRAY(ROWS(f))),1))
But if you have over 1000 values in col B, how do you expect to return a number between 1 & 100?
True, I need it to return a number between 1 and 1500
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
77,510
Office Version
  1. 365
Platform
  1. Windows
Glad to help.
 

Forum statistics

Threads
1,175,533
Messages
5,897,961
Members
434,688
Latest member
vi28

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
Top