如何每次创建一个唯一的号码 [英] How To create a unique number everytime

查看:75
本文介绍了如何每次创建一个唯一的号码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在文件系统上创建一个临时文件。我有超过5000个用户


什么是确保唯一性的最佳方法


感谢


Bill

I need to create a temporary file on the file system. I have over 5000 users

What''s the best method to ensure uniqueness

Thank

Bill

推荐答案

我需要在文件系统上创建一个临时文件。我有超过5000个用户。
确保唯一性的最佳方法是什么?
I need to create a temporary file on the file system. I have over
5000 users.
What''s the best method to ensure uniqueness?




取决于应用程序。你可能只是从#1开始就可以逃脱。

你可能会得到一系列布尔(或者一个布尔表格在数据库中的
),一个开始在#1等等。或者你可能需要

生成一个随机数并继续重试直到你没有使用

使用。


这完全取决于你需要多长时间才能做到这一点,负载是什么(你的同时是你的$ 5 $ b 5k用户?),等等。


如果计划正确,这可能会非常快。如果你去随机数

路线,请使用一个hige范围(即1到1,000,000之间的数字),以便

冲突是不太可能的。
< br $> b $ b -

gabriel



Depends on the application. You might get away with just starting at #1.
You might get away with having an array of booleans (or a table of booleans
in a database), one starting at #1 and so on. Or you might have to
generate a random number and keep retrying till you hi one that''s not in
use.

It all depends on how often you need to do this, what the load is (are your
5k users concurrent?), and so on.

This can be very fast if you plan it right. If you go the random number
route, use a hige range (ie, a number between 1 and 1,000,000) so that
conflicts are very unlikely.

--
gabriel


Guid myGuid = Guid.NewGuid();

myGuid.ToString(N);


您现在拥有一个唯一的32个字符的十六进制字符串。玩得开心。


Pete


-
http://www.petedavis.net

" gabriel" < no@no--spam.com>在消息中写道

新闻:b8 ************************** @ msgid.meganewsse rvers.com ...
Guid myGuid = Guid.NewGuid();
myGuid.ToString(N);

You now have a unique 32-character hex string. Have fun.

Pete

--
http://www.petedavis.net

"gabriel" <no@no--spam.com> wrote in message
news:b8**************************@msgid.meganewsse rvers.com...
我需要在文件系统上创建一个临时文件。我有超过5000个用户。
什么是确保唯一性的最佳方法?
取决于应用程序。你可能只是从#1开始就可以逃脱。
你可能会得到一系列布尔(或者数据库中的
I need to create a temporary file on the file system. I have over
5000 users.
What''s the best method to ensure uniqueness?
Depends on the application. You might get away with just starting at #1.
You might get away with having an array of booleans (or a table of



布尔表),一个开始在#1等等。或者你可能需要生成一个随机数并继续重试,直到你没有使用

这一切都取决于你需要做多少次这个,负载是什么(你的5k用户是
并发?),等等。

如果你正确计划,这可以非常快。如果你去随机数
路线,使用一个高度范围(即1到1,000,000之间的数字),这样就不太可能发生冲突。

- gabriel



" gabriel" < no@no--spam.com>在消息中写道

新闻:b8 ************************** @ msgid.meganewsse rvers.com ...
"gabriel" <no@no--spam.com> wrote in message
news:b8**************************@msgid.meganewsse rvers.com...
我需要在文件系统上创建一个临时文件。我有超过5000个用户。什么是确保唯一性的最佳方法?
I need to create a temporary file on the file system. I have over
5000 users. What''s the best method to ensure uniqueness?




Guid.NewGuid()。ToString()



Guid.NewGuid().ToString()


这篇关于如何每次创建一个唯一的号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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