'Generating easy to remember numbers
Is it possible to generate random numbers between say 1000000 and 9999999 that are easy to remember?
I know the term easy to remember
is relative but I'd believe that for your typical human being the number 331332 is easier to remember than 537106 (or is it?)
Use case. Am generating unique numbers for people in an application and was thinking I could try and make it easier for the people by assigning them easy numbers
. The way I'd play it is that the first people to register get the easy numbers and from there the easiness reduces.
If you've seen the same in any programming language you could post for inspiration to others
There's a similar question here but that was alphanumeric in nature and it was six years ago
Solution 1:[1]
Here I've found some things which make a number memorable: http://www.slideshare.net/cntryrckr69/what-makes-a-number-memorable
I've implemented it in python based on a few of these things
Here's what the code looks like:
import random
def easynum(num):
num = str(num)
if len(set(num)) <= 2: # common characters eg. 1114111
print("common")
return True
if num == num[::-1]: # its the same backwards eg. 1234321
print("reversible")
return True
if all(x <= y for x, y in zip(list(num), list(num)[1:])): # increasing, e.g. 123456789
print("increasing")
return True
if all(x >= y for x, y in zip(list(num), list(num)[1:])): # decreasing
print("decreasing")
return True
for count in range(10):
rand = random.randint(1000000, 9999999)
while easynum(rand) == None:
rand = random.randint(1000000, 9999999)
print(rand)
Here's the output I got:
reversible
5691965
reversible
9585859
increasing
1112557
reversible
9057509
reversible
3831383
decreasing
8322000
increasing
1122356
common
4884484
decreasing
9887320
common
4004040
Solution 2:[2]
I can think of a few easy to remember patterns:
1234321 (half reversed)
1234567 (in order)
1231231 (repeating)
7654321 (reverse order)
2468024 (even in order)
1357135 (odd in order)
1212121 (alternating)
There are obviously more you can think of. Have a library of different patterns. Randomly select a pattern from the library and then randomly populate that pattern, within the constraints of the pattern. For example, you can only select the starting digit of the 'in order' pattern, the following digits will depend on the starting digit.
Solution 3:[3]
One simple way is to randomly repeat your 0-9 digits different number of times; so making some digits more likely to appear than others.
import random
DIGITS = list(range(10))
def generate_easy_number(length=6):
multiplier = list(range(10))
random.shuffle(multiplier)
repeated_dig = list()
for i, n in enumerate(DIGITS):
for _ in range(multiplier[i]):
repeated_dig.append(n)
random.shuffle(repeated_dig)
return ''.join([str(x) for x in repeated_dig[:length]])
print(generate_easy_number())
So have your DIGITS list of 0-10, create another multiplier
list which is shuffled, then use its values to indicate how many repetitions (or weight) each digit would have.
Create the final list of duplicated digits, shuffle it and slice it.
Random results:
404092
090417
002657
840818
130610
065644
495060
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Tom Fuller |
Solution 2 | rossum |
Solution 3 | Alex R. |