生成属性的通用算法
Universal algorithm for generating properities
我需要制作算法,它采用随机唯一字符串(哈希等)并从预先配对的列表中生成多个随机属性。
示例:[猫算法]
color: white,black,brown
eye-color: blue, green, brown
size: 10,20,30
function algorithm(random_unique_hash){
...magic...
return [color, eye-color, size]
}
返回的猫对她的字符串来说绝对是独一无二的。
字符串在整个字符串列表中是唯一的。
每只猫都必须不同。
我需要能够从属性中再次进行哈希处理。
这可能吗?或者它需要以不同的方式工作?我是否需要制作 cat 然后制作唯一校验和?
从哪里开始?
您有三种颜色、三种眼睛颜色和三种尺码。这意味着您可以制作 3*3*3=27 种不同的猫。所以 random_unique_hash
应该只是一个从 0 到 26 的数字。
要从散列中获取属性,请使用除法和模运算符将散列分解为索引,例如
index1 = random_unique_hash % 3
index2 = (random_unique_hash / 3) % 3
index3 = random_unique_hash / 9
然后可以使用索引来访问每个 属性 列表中的正确条目。
要从属性中获取哈希值,您需要找到 属性 的索引。然后组合所有索引重新创建散列,像这样
random_unique_hash = index3 * 9 + index2 * 3 + index1
我需要制作算法,它采用随机唯一字符串(哈希等)并从预先配对的列表中生成多个随机属性。
示例:[猫算法]
color: white,black,brown
eye-color: blue, green, brown
size: 10,20,30
function algorithm(random_unique_hash){
...magic...
return [color, eye-color, size]
}
返回的猫对她的字符串来说绝对是独一无二的。 字符串在整个字符串列表中是唯一的。 每只猫都必须不同。 我需要能够从属性中再次进行哈希处理。
这可能吗?或者它需要以不同的方式工作?我是否需要制作 cat 然后制作唯一校验和?
从哪里开始?
您有三种颜色、三种眼睛颜色和三种尺码。这意味着您可以制作 3*3*3=27 种不同的猫。所以 random_unique_hash
应该只是一个从 0 到 26 的数字。
要从散列中获取属性,请使用除法和模运算符将散列分解为索引,例如
index1 = random_unique_hash % 3
index2 = (random_unique_hash / 3) % 3
index3 = random_unique_hash / 9
然后可以使用索引来访问每个 属性 列表中的正确条目。
要从属性中获取哈希值,您需要找到 属性 的索引。然后组合所有索引重新创建散列,像这样
random_unique_hash = index3 * 9 + index2 * 3 + index1