I've been trying for years to generate a list of unique random integers. Many people said it could not be done, others were stumped. Since I finally figured out a way to do it, I thought I would share since I have never found a solution that doesn't use a separate macro or script and involved multiple steps. I was always interested in something that could instantly re-generate without a great deal of effort.
In this example, I used randbetween(), but you could also use a rand() function to generate automatically without manually re-generating with ctrl shift f9.
This can, of course, scale down for smaller lists. I usually only need a few random numbers at a time, but I thought I would scale up to see if my processor could handle it. It did bog down a bit when I re-generate, but it only took a few seconds.
Comments/Questions?
[Solved] Generate Random Unique Integers
[Solved] Generate Random Unique Integers
- Attachments
-
- Generate Random Unique Numbers.ods
- (108.83 KiB) Downloaded 631 times
OpenOffice.org Version 3.4.0 Windows 7 Home Premium SP1 64-bit Operating System
Re: [Solved] Generate Random Unique Integers
Much easier:
Create a range of =RAND() as random seed.
Get the rank of each value: =RANK(SeedRange;SeedRange) [entered as array formula with Ctrl+Shift+Enter]
This creates an integer sequence of 1 ... Count(SeedRange). This may be used to pick random but unique values from a third range using the INDEX function.
Create a range of =RAND() as random seed.
Get the rank of each value: =RANK(SeedRange;SeedRange) [entered as array formula with Ctrl+Shift+Enter]
This creates an integer sequence of 1 ... Count(SeedRange). This may be used to pick random but unique values from a third range using the INDEX function.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Re: [Solved] Generate Random Unique Integers
I have tried that in the past but it is unreliable due to ranking issues where two rand() numbers are equal. And it happens more often than you would expect. I wanted something that didn't require checking to make sure there were no errors every time the sets of random numbers were generated.
OpenOffice.org Version 3.4.0 Windows 7 Home Premium SP1 64-bit Operating System
Re: [Solved] Generate Random Unique Integers
Thanks for this - it's awesome!!!MathHawk wrote:I've been trying for years to generate a list of unique random integers. Many people said it could not be done, others were stumped. Since I finally figured out a way to do it, I thought I would share since I have never found a solution that doesn't use a separate macro or script and involved multiple steps. I was always interested in something that could instantly re-generate without a great deal of effort.
In this example, I used randbetween(), but you could also use a rand() function to generate automatically without manually re-generating with ctrl shift f9.
This can, of course, scale down for smaller lists. I usually only need a few random numbers at a time, but I thought I would scale up to see if my processor could handle it. It did bog down a bit when I re-generate, but it only took a few seconds.
Comments/Questions?
Can you briefly explain how it works? It's a bit beyond my ken.
OpenOffice 3.3.0 on MacOS 10.11.4
- MrProgrammer
- Moderator
- Posts: 4908
- Joined: Fri Jun 04, 2010 7:57 pm
- Location: Wisconsin, USA
Re: [Solved] Generate Random Unique Integers
[Tutorial] Randomization in Calc, topic CMathHawk wrote:I've been trying for years to generate a list of unique random integers.
Mr. Programmer
AOO 4.1.7 Build 9800, MacOS 13.6.3, iMac Intel. The locale for any menus or Calc formulas in my posts is English (USA).
AOO 4.1.7 Build 9800, MacOS 13.6.3, iMac Intel. The locale for any menus or Calc formulas in my posts is English (USA).