UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> how to generate random non repeated numbers in php    
 
   
method
post Feb 6 2006, 01:34 PM
Post #1

UtterAccess Addict
Posts: 148



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


[B]$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";[/B]

$mycontent = "";
if (isset($_GET["sid"]))
{
   $allsid = explode (",",$_GET["sid"]);
   $mycontent = array();
   foreach ($allsid AS $value)
      $mycontent[] = $url[$value];
}

echo $mycontent;

[B]$handle = fopen ("ram.txt","w+");[/B]
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';
?>
Go to the top of the page
 
+
silasco
post Feb 8 2006, 07:33 AM
Post #2

UtterAccess Member
Posts: 49



you simply do some error checking.

<?php
$filename = random_filename();

if (file_exists($filename)) {
//try random generator again
} else {
//do something with file. like write to it;
}
?>
Go to the top of the page
 
+

Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Go to Top  ·  Lo-Fi Version Time is now: 26th May 2013 - 01:21 AM