如何写一个算法,它在一台上能每次产生一个随机并且唯一的序列?

解决方案 »

  1.   

    或者你模仿 guid的意思  定一个32位的字符数组数组的每一位都是从 “123...abcd...z”中随机选择出来的一个字符(使用rand()实现) ,产生的字符串重复的概率几乎为0
      

  2.   

    GetTickCount
    The GetTickCount function retrieves the number of milliseconds that have elapsed since the system was started. It is limited to the resolution of the system timer. If you need a higher resolution timer, use amultimedia timer or a high-resolution timer. 用 GetTickCount 的确最简单
      

  3.   

    哈哈,有道理,GetTickCount 绝对不重复。
    或者先随机产生一个数,再查找是否有重复的,有就再产生一次。
      

  4.   

    那还是不如用CoCreateGuid来的保险,都不用检查是否重复
      

  5.   

    GetTickCount 有一个问题就是 你下次重启系统 可能发生重复因为  The GetTickCount function retrieves the number of milliseconds that have elapsed “since the system was started ”.
      

  6.   

    GetTickCount得到的是系统开机以来运行的时间,以ms为单位,用一个DWORD来记录,有上限,超过上限后就归零重新计算,是有可能重复的,不过这机会实在小。
    CoCreateGuid我觉得比GetTickCount更可靠一点,毕竟用COM的人这么多,经得起考验。如果要求不是很严格的话,GetTickCount比较好,比较方便。