|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi all. could an expert show me how i can generate random non repeated numbers. I want to use those number as file name that i write to. currently the file name is ram.txt but i want it the file name to be like 948450913.txt each time the scripts runs diffrent number .I be happy if an expert show me how to do that here in this code?thanks
Code:
<?php
$url[1] = "http://localhost/flash_mp3_player/mp3/08 - Track 8.mp3";
$url[2] = "http://localhost/flash_mp3_player/mp3/13 - Gar Aya.mp3";
$url[3] = "http://localhost/flash_mp3_player/mp3/Soroush - Yeh Donya - 02 Shoghe Nafas.mp3";
$mycontent = "";
if (isset($_GET["sid"]))
{
$allsid = explode (",",$_GET["sid"]);
$mycontent = array();
foreach ($allsid AS $value)
$mycontent[] = $url[$value];
}
echo $mycontent;
$handle = fopen ("ram.txt","w+");
if ($handle)
{
if (fwrite ( $handle,implode("\r\n",$mycontent)."\r\n") )
{
echo "FILE IS WRITTEN SUCCESSFULLY";
} else
{
echo "ERROR IN WRITING TO FILE";
}
fclose ($handle);
} else
{
echo "ERROR IN OPENING FILE";
}
require 'config.txt';
?>
|
|
#2
|
|||
|
|||
|
bad idea, why not use sensible and useful filenames?
However, here's some pseudocode 1) generate random number rand() 2) check if that number is used ( store a list of used numbers in an array, database, file, glob through a dir etc) 3) if it isn't used, use it 4) if it is used, get another random number --Simon |
![]() |
| Viewing: ASP Free Forums > Other > Programming Help > How to generate random non repeated numbers in php |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|