生成用户友好代码 [英] Generate User Friendly Codes

查看:58
本文介绍了生成用户友好代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究生成随机的,对人类友好的代码,但是(不容易)猜测的方法.这将用于赠送奖品(请考虑唯一的折扣代码).我们将产生约50k.是否有任何标准的方法/算法来实现这一目标?我当时正在考虑使用GUID并应用CRC.这是个坏主意吗?

I am researching methods to generate a random human friendly code but not (easily) guessable. This will be used to give away prizes (think unique discount codes). We are to generate about 50k. Are there any standard methods/algorithms to accomplish this? I was thinking of using a GUID and applying CRC. Is this a bad idea?

如果有问题,请使用.netframework 3.5.

Using .netframework 3.5 if it matters.

推荐答案

我使用了 Base32 在此之前.

您只需要一个避免麻烦的字符(例如I,L,1、0,O等)的字母即可.

You just need an alphabet that avoids troublesome characters like I, L, 1, 0, O, etc.

编辑:因此,为澄清起见,仅Base32对足够随机生成的字节进行编码即可为您提供所需的字符数.

Edit: So, to clarify, just Base32 encode enough randomly generated bytes to give you the required number of characters.

然后,您可能希望将输出分成4组,以提高人类可读性.

Then you probably want split the output into groups of 4 for extra human readablity.

另一个好主意是使最后一个字母成为校验位-说出所有以前字节的模32之和.

Edit 2: Another good idea would be to make the last letter a check digit - say sum of all previous bytes modulo 32.

这篇关于生成用户友好代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆