生成易于记忆的随机标识符

发布于 2024-08-29 07:20:59 字数 1069 浏览 3 评论 0原文

与所有开发人员一样,我们在日常工作中不断处理某种标识符。大多数时候,它与错误或支持票有关。我们的软件在检测到错误后,会创建一个包,该包的名称由时间戳和版本号格式化,这是创建合理唯一标识符以避免混淆包的一种廉价方法。示例:“错误报告 20101214 174856 6.4b2”。

我的大脑不太擅长记住数字。我想要的是一种生成易于记忆的字母数字标识符的简单方法。

在 python 中创建如下所示的算法大约需要 5 分钟,它会产生一半可用的结果:

import random

vowels = 'aeiuy' # 0 is confusing
consonants = 'bcdfghjklmnpqrstvwxz'
numbers = '0123456789'

random.seed()

for i in range(30):
    chars = list()
    chars.append(random.choice(consonants))
    chars.append(random.choice(vowels))
    chars.append(random.choice(consonants + numbers))
    chars.append(random.choice(vowels))
    chars.append(random.choice(vowels))
    chars.append(random.choice(consonants))
    print ''.join(chars)

结果看起来像这样:

re1ean
meseux
le1ayl
kuteef
neluaq
tyliyd
ki5ias

这已经相当不错了,但我觉得仍然很容易忘记它们的准确拼写方式,所以如果你走到同事的办公桌前并想查看其中一张,仍然存在潜在的困难。

我知道有一些算法可以对文本进行三元组分析(假设你用德语给他们提供一整本书),并且可以生成看起来和感觉都像德语单词的字符串,因此通常更容易处理。不过,这需要大量数据,并且稍微不太适合为此目的嵌入到应用程序中。

您知道有任何已发布的算法可以解决这个问题吗?

谢谢!

卡尔

As all developers do, we constantly deal with some kind of identifiers as part of our daily work. Most of the time, it's about bugs or support tickets. Our software, upon detecting a bug, creates a package that has a name formatted from a timestamp and a version number, which is a cheap way of creating reasonably unique identifiers to avoid mixing packages up. Example: "Bug Report 20101214 174856 6.4b2".

My brain just isn't that good at remembering numbers. What I would love to have is a simple way of generating alpha-numeric identifiers that are easy to remember.

It takes about 5 minutes to whip up an algorithm like the following in python, which produces halfway usable results:

import random

vowels = 'aeiuy' # 0 is confusing
consonants = 'bcdfghjklmnpqrstvwxz'
numbers = '0123456789'

random.seed()

for i in range(30):
    chars = list()
    chars.append(random.choice(consonants))
    chars.append(random.choice(vowels))
    chars.append(random.choice(consonants + numbers))
    chars.append(random.choice(vowels))
    chars.append(random.choice(vowels))
    chars.append(random.choice(consonants))
    print ''.join(chars)

The results look like this:

re1ean
meseux
le1ayl
kuteef
neluaq
tyliyd
ki5ias

This is already quite good, but I feel it is still easy to forget how they are spelled exactly, so that if you walk over to a colleagues desk and want to look one of those up, there's still potential for difficulty.

I know of algorithms that perform trigram analysis on text (say you feed them a whole book in German) and that can generate strings that look and feel like German words and are thus easier to handle generally. This requires lots of data, though, and makes it slightly less suitable for embedding in an application just for this purpose.

Do you know of any published algorithms that solve this problem?

Thanks!

Carl

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

药祭#氼 2024-09-05 07:20:59

正如你所说,你的样本非常好。但如果您想要易于记住的随机标识符,那么您不应该混合字母数字和数字字符。相反,您可以选择在字母数字字符串后添加几个数字。

另外,在您的示例中,您明智地排除了“o”,但忘记了“l”,您很容易将其与“1”混淆。我建议您也删除“l”。 ;-)

As you said, your sample is quite good. But if you want random identifiers that can easily be remembered, then you should not mix alphanumeric and numeric characters. Instead, you could opt to postfix an alphanumeric string with a couple of digits.

Also, in your sample You wisely excluded 'o', but forgot about the 'l', which you can easily confuse with '1'. I suggest you remove the 'l' as wel. ;-)

杯别 2024-09-05 07:20:59

我不确定这是否回答了您的问题,但也许想一下您需要多少个唯一的错误报告编号。

只需使用四个字母的大写字母数字键(例如“BX-3D”),您就可以获得 36^4 = 170 万个错误报告。

编辑:我刚刚看到了您的示例。如果您使用音节而不是辅音和元音,也许结果会大大改善。

I am not sure that this answers your question, but maybe think about how many unique bug report number you need.

Simply using a four letter uppercase alphanumeric key like "BX-3D", you can have 36^4 = 1.7 million bug reports.

Edit: I just saw your sample. Maybe the results could be considerably improved if you used syllables instead of consonants and vowels.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文