如何生成随机唯一字母数字? [英] How to generate Random Unique alpha numeric numbers?

查看:117
本文介绍了如何生成随机唯一字母数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi
Sir / Mam

我是一个更新鲜的人,我有一个应用程序,需要自动生成一个独特的字母数字ID(没有重复)。我想自定义我自己选择的字母。

例如:

如果我需要为学生生成一个录取号码

如果学院名称是sathya id应该看起来像-------- sa00001

-------- sa00002

它们应该是唯一的,永远不会产生重复。怎么样?





请帮帮我

先谢谢

Hi Sir/Mam
I'am a fresher and i have an application that requires to generate a unique alphanumeric id automatically(with out duplicates).and i want to customize the alphabets to my own choice.
For example:
if I need to generate a admission number for a student
if the college name is sathya the id should look like -------- sa00001
-------- sa00002
and they should be unique and never generate a duplicate.How?


Please Help me Out
Thanks In advance

推荐答案

首先从数据库中获取表的最后一个id。

然后解析它

例如在您的情况下:

First of all get the last id of the table from database.
Then parse it
e.g. in your situation:
var numAlpha = new Regex("(?<Alpha>[a-zA-Z]*)(?<Numeric>[0-9]*)");
            var match = numAlpha.Match("sa00001");
            var alpha = match.Groups["Alpha"].Value;
            var num = match.Groups["Numeric"].Value;
            var number = Convert.ToInt32(num);
            ++number;
            var nextId = alpha;
            var length = num.Length - number.ToString().Length;
            if (length != 0)
            {
                var format = "D" + length;
                nextId += number.ToString(format);
            }
else{
nextId+=number.ToString();
}





现在你有下一个id做你能做的任何事情



Now you have next id do whatever you can do with it


访问这里.....





Generate-random-8-character-alphanumeric-strings-in-c [ ^ ]
visit here.....


Generate-random-8-character-alphanumeric-strings-in-c[^]


使用GUID生成唯一ID,然后将(您的组合的字符串)附加到Uniquely生成的密钥,就像这样的帖子 soverflow [ ^ ]



我认为这样可以解决您的问题。
Generate a unique ID using GUID and then append the string (of your combination to the Uniquely generated key) like this a post in soverflow[^]

I think this will resolve your issue.


这篇关于如何生成随机唯一字母数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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