如何为用户自动生成唯一的假名?

发布于 2024-08-02 23:19:02 字数 348 浏览 1 评论 0原文

我们希望为每个用户提供一个别名,以便我们可以在讨论中引用他们,同时保护他们的身份。这些别名应该是唯一的。

简单的方法是简单地使用 SERIAL 列,但整数并不容易记住。我们希望使用真实的人名,以便我们可以记住别名。

其他简单的方法是在某处找到名字列表,对它们进行编号,然后使用 SERIAL 从列表中获取名字。当列表用完时,添加更多名称。

但是有没有一些聪明的方法将整数映射到名称?

我们目前拥有大约 2,000 名用户,并且还在不断增长,但我怀疑我们是否会成为 Google。

We would like to give each of users an alias so that we can refer to them in discussions while protecting their identity. These aliases should be unique.

The easy way would be to simply use a SERIAL column, but ints aren't memorable. We would like to use real people names so that we can remember the aliases.

The other easy way would be to find a list of first names somewhere, number them, and use a SERIAL to fetch names from the list. When the list runs out, add more names.

But is there some clever way to map ints to names?

We currently have about 2,000 users and are growing, but I doubt we'll ever become Google.

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

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

发布评论

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

评论(4

围归者 2024-08-09 23:19:02

这听起来可能很疯狂。但是游戏编程中使用一种算法来创建无意义但发音独特的名称,例如 Alveolar,双唇音、声门音、腭音、软腭音。

It may sound crazy. But there is an algorithm used in game programming to create meaningless but phonetically unique names like Alveolar, Bilabial, Glottal, Palatal, Velar.

野侃 2024-08-09 23:19:02

人口普查局的姓名文件中随机选择一个姓名。

Pick a random name from the Census Bureau's names file.

成熟的代价 2024-08-09 23:19:02

您是否尝试过哈希函数?我不确定它们是否在 Postgres 中可用。但是,是的,一种方法是让内部哈希函数来处理。他们将输出唯一的 ID。

Have you tried any Hash functions? I am not sure whether they are available in Postgres. But yeah, one way to do is let the internal hash function take care. They will output unique IDs.

递刀给你 2024-08-09 23:19:02

回到“那个时代”,Compuserve(或者是 AOL?)曾经通过有两个单词列表并从每个列表中取出一个单词并将其放在一起来给出临时的初始密码,这样你就会得到像 EasyTomato 之类的东西。也许类似的东西适合您的用户群。如果每个单词列表有 256 个字符,则有 65535 个唯一组合(请注意,只需递增 16 位整数即可轻松选择组合)。

编辑:毕竟不要对整数进行直接递增,否则前 256 个人都会得到相同的第一个单词,但基本思想仍然是合理的。选择一个随机的、尚未使用的 16 位数字。高 8 位是第一个单词列表的索引,低 8 位是第二个单词列表的索引。

Back in "the day" Compuserve (or was it AOL?) used to give out temporary, initial passwords by having two lists of words and taking one word from each list and putting it together, so you would get something like EasyTomato or whatever. Perhaps something like that would work for your user base. If each word list has 256 characters, that's 65535 unique combinations (and notice how easily you can pick the combination by just incrementing a 16-bit integer).

EDIT: Well don't do a straight increment of the integer after all, or the first 256 people will all get the same first word, but the basic idea is still sound. Pick a random, not-yet-used 16-bit number. High 8 bits are your index into the first word list, low 8 bits are your index into the second word list.

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