在C ++开源随机数生成算法? [英] Open source random number generation algorithm in C++?

查看:114
本文介绍了在C ++开源随机数生成算法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要生成随机数范围为1 - 10000不断与出重复。 任何建议?

I need to generate random numbers in the range 1 - 10000 continuously with out duplication. Any recommendations?

说明:我们正在建设一个新的版本,我们的应用程序,它保持在SQLite的数据库记录。在我们的应用程序的最后一个版本,我们并没有唯一键为每个记录。但现在新的升级版本,我们需要支持的最后一个版本的DB的进口设备。所以,我们要做的是,我们看到从旧的数据库的每一个记录,并生成一个随机数为独特的密钥并将其存储在新的数据库。在这里,我们很多需要进口多达10000条记录不断。

Description: we are building a new version for our application, which maintains records in Sqlite DB. in the last version of our application, we did not had unique key for each record. But now with new upgraded version, we need to support the import facility from the last version's DB. So what we do is, we read each and every record from the old DB and generate a random number for the unique key and store it in new DB. Here we many need to import up to 10000 records continuously.

推荐答案

如果真的必须在1至10,0000的范围内无重复,但非连续的,则它很可能是最好先创建一个连续的数组10000的元素,然后洗牌它们。

If it really must be in the range of 1 to 10,0000 without repeats, but non-sequential then it would probably be best to first create a sequential array of 10000 elements, and then shuffle them.

不过,我必须同意与原来问题的意见。我看到了让他们不连续的没有价值。

However, I must agree with the comments on the original question. I see no value in making them non- sequential.

另外,独特的&放大器;非顺序是重要的,则1至10,000范围成为疑问。或许,这将是最好的只用一个GUID。

Alternately, in unique & non-sequential are important, then the 1 to 10,000 range become questionable. It would probably be best to just used a GUID.

这篇关于在C ++开源随机数生成算法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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