2

我想从几个类属性创建一个唯一的、人类可读的 ID,例如:

Class A contains property c,d,e
Class B contains property f,g

所以一个 ID 代表

c=1
d=2
e=3
f=4
g=5

而另一个 ID 将代表

c=7
d=3
e=4
f=0
g=11

为了参数,属性只是整数(编辑:在 0 到 1000 的范围内),而实际上它们实际上也可以是浮点数和字符串。

我正在寻找一种方法将这些值组合成一个简短的、人类可读的 ID。此外,我希望能够从 ID 重建属性。此外,如果可能,属性的微小差异也会导致 ID 的微小差异。

这是一个我认为小且易于阅读的示例: H5RT33

有没有类似的算法?

编辑:我写下了 ID 示例,同时期待诸如“什么是人类可读的?”之类的问题。我发现这很难描述——例如,MD5 就不会,而像“树”这样的真实单词是不必要的。所以给出的 ID 有点在中间,但我并不是要将它限制为 6 个字符,或者只有大写字母和数字。

另外,我谈到了整数,而我真正的意思是“0-1000 范围内的整数”。

4

1 回答 1

3

You want an invertible transformation (a bijection), which means that the information content of both original and transform are the same. A six-character alphanumeric code using only capital letters, as in H5RT33 has 366 possible values; in other words, it has 6 * log236 = 31.1 bits of information. Five (32-bit) integers, on the other hand, contain 5 * 32 = 180 bits, which is quite a bit more (unless, of course, the integers have a restricted range). And you say you'd also like to encode floating point numbers and strings, which contain quite a bit more information.

So on strictly information-theoretic grounds, I think you're going to have a hard time fulfilling all of your requirements.

于 2013-03-05T18:27:27.977 回答