Named range of consecutive random numbers

Background

Following the question that I asked some time ago about getting an array of different (but not necessarily unique) random numbers, to which the answer was received:

=RANDBETWEEN(ROW(A1:A10)^0,10) 

To get an array of 10 random numbers from 1 to 10

Problem

If I create a named range (called "randArray") with the above formula, I was hoping I could refer to randArray several times and get a set of identical random numbers. Of course, they will change every time I press F9 or update the worksheet, but change them together.

This is what I get instead, two completely different sets of random numbers

enter image description here

I am not surprised by this behavior, but how can I achieve this without using VBA and not putting random numbers on the worksheet ?

<h / "> If you are interested

This example is for MCVE. In my actual case, I use random numbers to estimate Pi. The user determines how many random points to apply and receives an accurate estimate accordingly. The problem arises from the fact that I also draw points, and when there are a small number of points, it is very clear to see that the score and the graph do not represent the same data set


Update

I awarded @Michael's initial award for providing an interesting and different solution. I'm still looking for a complete solution that allows the user to determine how many random points to use, and although there may not be a perfect answer, I'm still interested in any other possible solutions and am more than happy to carry further bounties.

Thanks to everyone who has contributed so far.

+7
arrays random excel excel-formula
source share
3 answers

This solution generates 10 seemingly random numbers from 1 to 10, which are stored for almost 9 seconds at a time. This allows you to repeat calls to the same formula to return the same set of values โ€‹โ€‹in one update.

If necessary, you can change the time frame. Shorter time periods allow more frequent updates, but also slightly increase the extremely unlikely probability that some formula calls appear after the intersection point, which will lead to a 2nd set of 10 random numbers for subsequent calls.

First define an array of "Primes" with 10 different primes:

 ={157;163;167;173;179;181;191;193;197;199} 

Then define this formula that will return an array of 10 random numbers:

 =MOD(ROUND(MOD(ROUND(NOW(),4)*70000,Primes),0),10)+1 

Explanation:

We need to build our own random number generator, which we can sow with the same value for some time; long enough for the called formula to keep the same value.

First, we create a seed: ROUND(NOW(),4) creates a new seed number every 0.0001 days = 8.64 seconds.

We can generate rough random numbers using the following formula:

Random = Seed * 7 mod Prime

https://cdsmith.wordpress.com/2011/10/10/build-your-own-simple-random-numbers/

Ideally, a sequence of random numbers is generated by inputting input from the previous output, but we cannot do this in one function. Thus, instead, it uses 10 different primes, essentially starting 10 different random number generators. Now this has less reliability when generating random numbers, but the test results below show that it actually looks pretty good.

ROUND(NOW(),4)*70000 gets our seed to an integer and multiplies by 7 at the same time

MOD(ROUND(NOW(),4)*70000,Prime) generates a sequence of 10 random numbers from 0 to the corresponding prime

ROUND(MOD(ROUND(NOW(),4)*70000,Prime),0) is required to return us to an integer, because Excel seems to be trying to use Mod for floating point numbers.

=MOD(ROUND(MOD(ROUND(NOW(),4)*70000,Prime),0),10)+1 takes only the value from one place (random number from 0 to 9) and shifts it to give us a random number from 1 to 10

Test results:

I produced 500 lots of 10 random numbers (in columns instead of rows) for initial values โ€‹โ€‹increasing by 0.0001, and counted the number of times each digit took place for each prime number. You can see that each digit occurred almost 500 times and that the distribution of each digit is almost equal between each prime number. Thus, this may be adequate for your purposes.

Looking at the numbers generated in the immediate sequence, you can see the similarities between adjacent primes, they are not exactly the same, but they are pretty close in places, even if they are offset by several lines. However, if the update occurs at random intervals, you will still receive random numbers, and this should be enough for your purposes. Otherwise, you can apply this approach to a more complex random number generator or try a different combination of primes that are further apart.

results

Update 1: Trying to find a way to indicate the number of random numbers generated without saving a list of primes.

Attempt 1: using a single simple with an array of seeds:

 =MOD(ROUND(MOD(ROUND(NOW()+ROW(OFFSET(INDIRECT("A1"),0,0,SampleSize))/10000,4)*70000,1013),0),10)+1 

This gives you an even distribution, but actually it just repeats the same sequence of 10 numbers over and over. Any analysis of the sample would be identical to the analysis =MOD(ROW(1:SampleSize),10)+1 . I think you want more options than this!

Attempt 2: Work on a two-dimensional array that still uses 10 primes ....

Update 2: Doesn't work. He had a terrible performance. A new answer was presented using a similar but different approach.

+1
source share

OK, here is a solution where users can specify the number of values โ€‹โ€‹in a specific name SAMPLESIZE

 =MOD(ROUND(MOD(ROUND(NOW()+ROW(OFFSET(INDIRECT("A1"),0,0,SampleSize)),4)*10000*163,1013),0)+ROUND(MOD(ROUND(NOW()+ROW(OFFSET(INDIRECT("A1"),0,0,SampleSize))*2,4)*10000*211,1013),0)+ROUND(MOD(ROUND(NOW()+ROW(OFFSET(INDIRECT("A1"),0,0,SampleSize))*3,4)*10000*17,1013),0)+ROUND(MOD(ROUND(NOW()+ROW(OFFSET(INDIRECT("A1"),0,0,SampleSize))*5,4)*10000*179,53),0)+ROUND(MOD(ROUND(NOW()+ROW(OFFSET(INDIRECT("A1"),0,0,SampleSize))*7,4)*10000*6101,1013),0),10)+1 

This is a long formula, but has good efficiency and can be used in other functions. Attempts to get a shorter formula led to unusually low performance and arrays, which for some reason could not be used in other functions.

This solution combines 5 different prime generators to increase variety in the generated random numbers. Some arbitrary constants were introduced to try to reduce duplicate patterns.

This has the correct distribution and pretty good randomness. Repeated testing with SampleSize of 10,000 led to the fact that the frequencies of individual numbers ranged from 960 to 1040 without general favoritism. However, it seems like a strange property to never generate the same number twice in a row!

+1
source share

This is not a great answer, but given the limitation of the volatile function, it is definitely a possible response to using the IF formula with the Volatile function and the volatile variable located somewhere on the sheet.

I used the formula below to achieve the desired result

 =IF(rngIsVolatile,randArray,A1:A10) 

I set cell B12 as rngIsVolatile. I pasted the screenshots below to see it work.

IF Formula to Limit Volatility Volatility

When rngIsVolatile is set to True, it gets the new values โ€‹โ€‹from randArray: Function Result volatile # 01

When rngIsVolatile is set to False, it takes the old values โ€‹โ€‹from A1: A10: Function Result volatile # 02

-one
source share

All Articles