如何生成随机数,同时避免使用已使用的数字 [英] How do generate random numbers, while avoiding numbers already used

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

问题描述

我如何生成随机数,但要避免使用已经使用过的数字.我有一个包含成千上万个数字的TXT文件,我需要在避免这些数字的同时生成一系列随机数.

How do i generate random numbers but have the numbers avoid numbers already used. I have a TXT file with thousands of sets of numbers and i need to generate a series of random numbers while avoiding these.

IE,TXT-0102030405
我的随机数需要避免使用此数字.

IE, TXT - 0102030405
my random number needs to avoid this number.

在旁注中,如何将TXT 10位数字分成5位和两位数字?那么我如何基于此生成随机数.

on a side note, how can i split up the TXT 10 digit number into 5, two digit numbers? then how can i generate random numbers based off of that.

推荐答案

如果您需要维护文件(我想这样做,以便添加新数字),建议您使用纯文本忘记"文本文件,并使用SQLite或文件中备份的任何其他嵌入式DB,因为您可能不想将所有数字加载到内存中.

If you need to maintain the file (which I think you do, in order to add new numbers), I would suggest you to "forget" using a plain text file and use SQLite or any other embedded DB that is backed up in a file, as you probably don't want to load all the numbers in memory.

SQLite想要的功能"(或更确切地说,数据结构)是B树,因此您可以快速检索数字.我说这是因为,您还可以尝试找到实现B树的库,这样就不需要SQLite.

The "feature" (or better said, data structure) you want from SQLite is a B-Tree, so you can retrieve the numbers fast. I'm saying this, because you could also try to find a library that implements B-Trees, and then you wouldn't need SQLite.

这篇关于如何生成随机数,同时避免使用已使用的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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