dongtiannai0654 2014-08-26 08:41
浏览 85
已采纳

创建独特的随机字符串

I am working in php and I am trying to create 1000 tickets in a database. Each ticket needs it's own unique code that consists of letters and numbers about 6 characters long.

EXP.    
Tbl_Tickets
ID     code
1      3F2jk7
2      2HGUF1       
3      9FJDNJ
4      MFJEY9
5      23988D

I was wondering is there a simple way of doing this with php, or excel, or any other way for that matter. I know that i can use a random number generator, but the check for the Unique would have a large BigO notation and the check would get messy.

  • 写回答

4条回答 默认 最新

  • dongluobei9359 2014-08-26 08:57
    关注

    Unique is not compatible with random, but the following might suit:

    =CHOOSE(RANDBETWEEN(1,2),RANDBETWEEN(0,9),CHAR(RANDBETWEEN(65,90)))

    copied across to populate six columns (say A to F) with, in G:

    =A1&B1&C1&D1&E1&F1

    and both copied down to say row 1100. Then select G, copy Paste Special Values, and Remove Duplicates on ColumnG and select first 1000 entries.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部