Skip to content
This repository has been archived by the owner on Sep 10, 2021. It is now read-only.

Commit

Permalink
Replace rand() with mt_rand()
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamie Snape committed Jul 14, 2014
1 parent 2f0df14 commit 132c42b
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 24 deletions.
8 changes: 4 additions & 4 deletions core/controllers/UserController.php
Expand Up @@ -874,7 +874,7 @@ public function settingsAction()
return;
}

$tmpPath = $this->getDataDirectory('thumbnail').'/'.rand(1, 1000);
$tmpPath = $this->getDataDirectory('thumbnail').'/'.mt_rand(1, 1000);
if(!file_exists($this->getDataDirectory('thumbnail')))
{
throw new Zend_Exception("Thumbnail path does not exist: ".$this->getDataDirectory('thumbnail'));
Expand All @@ -883,15 +883,15 @@ public function settingsAction()
{
mkdir($tmpPath);
}
$tmpPath .= '/'.rand(1, 1000);
$tmpPath .= '/'.mt_rand(1, 1000);
if(!file_exists($tmpPath))
{
mkdir($tmpPath);
}
$destionation = $tmpPath."/".rand(1, 1000).'.jpeg';
$destionation = $tmpPath."/".mt_rand(1, 1000).'.jpeg';
while(file_exists($destionation))
{
$destionation = $tmpPath."/".rand(1, 1000).'.jpeg';
$destionation = $tmpPath."/".mt_rand(1, 1000).'.jpeg';
}
$pathThumbnail = $destionation;

Expand Down
2 changes: 1 addition & 1 deletion core/controllers/components/ExportComponent.php
Expand Up @@ -166,7 +166,7 @@ function exportBitstreams($userDao, $targetDir, $itemIds, $shouldSymLink)
// have the same file name, add a '.new' suffix to distinguish them
if(file_exists($dest))
{
$dest .= '.'.rand().'.new';
$dest .= '.'.mt_rand().'.new';
}
if(!symlink($source, $dest))
{
Expand Down
2 changes: 1 addition & 1 deletion core/controllers/components/UtilityComponent.php
Expand Up @@ -700,7 +700,7 @@ public static function generateRandomString($length, $alphabet = null)
$max = strlen($alphabet) - 1;
for($i = 0; $i < $length; $i++)
{
$salt .= substr($alphabet, rand(0, $max), 1);
$salt .= substr($alphabet, mt_rand(0, $max), 1);
}
return $salt;
}
Expand Down
4 changes: 1 addition & 3 deletions core/controllers/forms/ImportForm.php
Expand Up @@ -32,9 +32,7 @@ public function createImportForm($assetstores)
$form->setAttrib('class', 'importForm');

// Hidden upload id
srand(time());

$uploadId = new Zend_Form_Element_Hidden('uploadid', array('value' => rand()));
$uploadId = new Zend_Form_Element_Hidden('uploadid', array('value' => mt_rand()));
$uploadId->setDecorators(array(
'ViewHelper',
array('HtmlTag', array('style' => 'display:none')),
Expand Down
4 changes: 2 additions & 2 deletions core/models/base/ItemRevisionModelBase.php
Expand Up @@ -127,10 +127,10 @@ function addBitstream($itemRevisionDao, $bitstreamDao)
{
throw new Zend_Exception("Problem thumbnail path: ".UtilityComponent::getDataDirectory('thumbnail'));
}
$destination = $tmpPath.'/'.rand(1, 10000).'.jpeg';
$destination = $tmpPath.'/'.mt_rand(1, 10000).'.jpeg';
while(file_exists($destination))
{
$destination = $tmpPath.'/'.rand(1, 10000).'.jpeg';
$destination = $tmpPath.'/'.mt_rand(1, 10000).'.jpeg';
}
$pathThumbnail = $destination;

Expand Down
4 changes: 2 additions & 2 deletions core/models/pdo/UserapiModel.php
Expand Up @@ -111,13 +111,13 @@ function getToken($email, $apikey, $appname)

// seed with microseconds
list($usec, $sec) = explode(' ', microtime());
srand((float) $sec + ((float) $usec * 100000));
mt_srand((float) $sec + ((float) $usec * 100000));

$token = "";
$max = strlen($keychars) - 1;
for($i = 0; $i < $length; $i++)
{
$token .= substr($keychars, rand(0, $max), 1);
$token .= substr($keychars, mt_rand(0, $max), 1);
}

// Find the api id
Expand Down
Expand Up @@ -234,10 +234,10 @@ public function resultsserver($args)
mkdir(UtilityComponent::getTempDirectory().'/remoteprocessing');
}

$destionation = UtilityComponent::getTempDirectory().'/remoteprocessing/'.rand(1, 1000).time();
$destionation = UtilityComponent::getTempDirectory().'/remoteprocessing/'.mt_rand(1, 1000).time();
while(file_exists($destionation))
{
$destionation = UtilityComponent::getTempDirectory().'/remoteprocessing/'.rand(1, 1000).time();
$destionation = UtilityComponent::getTempDirectory().'/remoteprocessing/'.mt_rand(1, 1000).time();
}
mkdir($destionation);

Expand Down
Expand Up @@ -115,10 +115,10 @@ public function createThumbnailFromPath($name, $fullPath, $width, $height, $exac
{
throw new Zend_Exception('Temporary thumbnail dir does not exist: '.UtilityComponent::getDataDirectory('thumbnail'));
}
$destination = $tmpPath.'/'.rand(1, 10000).'.jpeg';
$destination = $tmpPath.'/'.mt_rand(1, 10000).'.jpeg';
while(file_exists($destination))
{
$destination = $tmpPath.'/'.rand(1, 10000).'.jpeg';
$destination = $tmpPath.'/'.mt_rand(1, 10000).'.jpeg';
}
$pathThumbnail = $destination;

Expand Down Expand Up @@ -198,7 +198,7 @@ public function preprocessByThumbnailer($name, $fullpath)
$jpegDestination = $tmpPath.'/'.$name.'.jpeg';
while(file_exists($jpegDestination))
{
$jpegDestination = $tmpPath.'/'.$name.rand(1, 10000).'.jpeg';
$jpegDestination = $tmpPath.'/'.$name.mt_rand(1, 10000).'.jpeg';
}
$modulesConfig = Zend_Registry::get('configsModules');
$thumbnailerPath = $modulesConfig['thumbnailcreator']->thumbnailer;
Expand Down
8 changes: 4 additions & 4 deletions modules/visualize/controllers/components/MainComponent.php
Expand Up @@ -451,7 +451,7 @@ public function processParaviewData($itemDao)
return;
}

$thumbnailPath = UtilityComponent::getDataDirectory('thumbnail').'/'.rand(1, 1000);
$thumbnailPath = UtilityComponent::getDataDirectory('thumbnail').'/'.mt_rand(1, 1000);
if(!file_exists(UtilityComponent::getDataDirectory('thumbnail')))
{
throw new Zend_Exception("Problem thumbnail path: ".UtilityComponent::getDataDirectory('thumbnail'));
Expand All @@ -460,15 +460,15 @@ public function processParaviewData($itemDao)
{
mkdir($thumbnailPath);
}
$thumbnailPath .= '/'.rand(1, 1000);
$thumbnailPath .= '/'.mt_rand(1, 1000);
if(!file_exists($thumbnailPath))
{
mkdir($thumbnailPath);
}
$destionation = $thumbnailPath."/".rand(1, 1000).'.jpeg';
$destionation = $thumbnailPath."/".mt_rand(1, 1000).'.jpeg';
while(file_exists($destionation))
{
$destionation = $thumbnailPath."/".rand(1, 1000).'.jpeg';
$destionation = $thumbnailPath."/".mt_rand(1, 1000).'.jpeg';
}
$pathThumbnail = $destionation;

Expand Down
2 changes: 1 addition & 1 deletion tests/ControllerTestCase.php
Expand Up @@ -53,7 +53,7 @@ public function stopCodeCoverage()
xdebug_stop_code_coverage();

$file = CMAKE_BINARY_DIR.'/xdebugCoverage/'.md5($_SERVER['SCRIPT_FILENAME']);
file_put_contents($file.'.'.md5(uniqid(rand(), true)).'.'.get_class($this), serialize($data));
file_put_contents($file.'.'.md5(uniqid(mt_rand(), true)).'.'.get_class($this), serialize($data));
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/DatabaseTestCase.php
Expand Up @@ -51,7 +51,7 @@ public function stopCodeCoverage()
xdebug_stop_code_coverage();

$file = CMAKE_BINARY_DIR.'/xdebugCoverage/'.md5($_SERVER['SCRIPT_FILENAME']);
file_put_contents($file.'.'.md5(uniqid(rand(), true)).'.'.get_class($this), serialize($data));
file_put_contents($file.'.'.md5(uniqid(mt_rand(), true)).'.'.get_class($this), serialize($data));
}
}

Expand Down

0 comments on commit 132c42b

Please sign in to comment.