LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-09-2009, 03:20 PM   #1
frieza
Senior Member
 
Registered: Feb 2002
Location: harvard, il
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,233

Rep: Reputation: 406Reputation: 406Reputation: 406Reputation: 406Reputation: 406
question about seeding mt_rand in php


here's a simple script i wrote using gdlib rendering to create a random forum sig for other forums (no img tags in this forum
Code:
<?php
$me = mt_rand(1,78);
$pic=imagecreatefromjpeg($me.".jpg");
list($width, $height, $type, $attr) = getimagesize($me.".jpg");
$layer = imagecreatetruecolor  ( 250  , 250  );
$blue = imagecolorallocate  ( $layer  , 0  , 0  , 0  );
imagefill($layer,0,0,$blue);
$white = imagecolorallocate  ( $layer  , 204  , 255  , 255  );
imagecopyresampled  ( $layer  , $pic  , 0  , 35  , 0  , 0  , 250  , 215  , $width  , $height  );
imagefttext($layer,25,0,60,30,$white,"./Norasi-Oblique.ttf","HOPPER" );
header("Content-type: image/jpeg");
imagejpeg($layer);
imagedestroy($layer);
imagedestroy($pic);
?>
granted i know seeding the random number generator is no longer explicitly necessary, but how could i seed the random number to decrease the likelyhood of duplicates when this script is called multiple times from the same page?
 
Old 04-09-2009, 05:52 PM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Quote:
Originally Posted by frieza View Post
i know seeding the random number generator is no longer explicitly necessary, but how could i seed the random number to decrease the likelyhood of duplicates when this script is called multiple times from the same page?
If the PHP docs say it is not needed, it is probably the best not to do it. If you would seed the readnom generator every time you script is called from some web page, the random numbers would becom much more predictable.

If you do it, the important thing is to make sure it is done once.
 
Old 04-09-2009, 08:52 PM   #3
frieza
Senior Member
 
Registered: Feb 2002
Location: harvard, il
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,233

Original Poster
Rep: Reputation: 406Reputation: 406Reputation: 406Reputation: 406Reputation: 406
fair enough, any ideas perhaps on how to reduce the chance of getting duplicates when being displayed say.. 9 times?
 
Old 04-09-2009, 09:02 PM   #4
frieza
Senior Member
 
Registered: Feb 2002
Location: harvard, il
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,233

Original Poster
Rep: Reputation: 406Reputation: 406Reputation: 406Reputation: 406Reputation: 406
figured it out i think using setcookie
nvm it didnt work

Last edited by frieza; 04-09-2009 at 10:09 PM.
 
Old 04-10-2009, 01:14 AM   #5
frieza
Senior Member
 
Registered: Feb 2002
Location: harvard, il
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,233

Original Poster
Rep: Reputation: 406Reputation: 406Reputation: 406Reputation: 406Reputation: 406
how does this page appear to you?
http://hoppernet.rubiesofeventide.org/testpage.html
 
Old 04-10-2009, 03:40 AM   #6
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Quote:
Originally Posted by frieza View Post
how does this page appear to you?
http://hoppernet.rubiesofeventide.org/testpage.html
9 times the same picture.
But every page load it is a different picture.

Is that what you intended? Or did you want 9 different pictures each time?
 
Old 04-10-2009, 08:40 PM   #7
frieza
Senior Member
 
Registered: Feb 2002
Location: harvard, il
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,233

Original Poster
Rep: Reputation: 406Reputation: 406Reputation: 406Reputation: 406Reputation: 406
i was hoping for 9 pictures each time.. which is funny because that's what i see
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Deluge seeding issue whizkid25 Linux - Software 0 12-12-2007 07:49 PM
seeding with ktorrent? johngreenwood Linux - Newbie 2 11-18-2006 04:21 AM
Seeding on bittorrent conanm4 Ubuntu 2 09-27-2006 07:48 AM
Seeding distros on bittorent conanm4 Linux - General 1 09-15-2006 11:21 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:50 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration