Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a seed for random number generation

From what I understand, there is no built-in function in Google Sheets that allows you to set a seed for RAND() or RANDBETWEEN().

My goal is to create a list of psuedo-random integers, within a range, using a function that will produce different (though, not necessarily unique) values based on:

  • Which cell is running the function
  • And the value in a second cell that contains a seed of my choosing

I need it to produce the same value every time the function is run in a particular cell, with a particular seed.

What is the simplest way to achieve this, so that someone who isn't me and has no programming knowledge can easily use the formula in other cells, as they need to?

like image 492
user7133934 Avatar asked Oct 16 '25 14:10

user7133934


1 Answers

Short answer

Use VLOOKUP and ADDRESS

Explation

Create a simple table with two columns, one for a compound key made from the cell address and the "seed" the other for the "seudo-random integers" (SRI)

Simple table

Sheet name: Table

Sheet content (for illustrative purposes):

 |  A   |  B   | 
1|key   |  SRI |
2|A1-1  |    1 |
3|A1-2  |   77 |

Formula

=VLOOKUP(ADDRESS(ROW(),COLUMN(),4,FALSE)&"-1",Table!A2:B,2,0)
like image 188
Rubén Avatar answered Oct 18 '25 10:10

Rubén



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!