Home > Backend Development > PHP Tutorial > PHP如何生成1万条不重复数据,

PHP如何生成1万条不重复数据,

WBOY
Release: 2016-06-23 14:04:05
Original
1223 people have browsed it

请教:PHP如何生成1万条不重复数据


回复讨论(解决方案)

一万条怎样的数据  

1-10000也是不重复的阿  

每次要生成一万条(以上),而且是数字组成。每条数据要17位

组织一个17位的现在的时间(精确到秒)数值加1,然后从1到10000,每次都用当前时间加循环的数值,应该不会有重的

$fn = '随机数.txt';for($i=0; $i<10000; $i++) {  file_put_contents($fn, sprintf('%07d%08d', rand(0, 9999999), rand(0, 99999999)).PHP_EOL, FILE_APPEND);}
Copy after login

文件 随机数.txt 中就是你要的结果

时间可以用时间戳来表示

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template