Jump to content

help with a random number generator.


slapdashwebdesign

Recommended Posts

I have created a script to attempt to make random images appear.

to see it in action go to http://slapdash.grimhq.com/imagerotater/imagerotator.php.

 

the problem i am having is the repeating of images.

i have tried to create it so it would not repeat but it does not work. there must be a better way.

here is my script.

help please.

<?php
//create a random value for each circle
$cir1 = rand(1,5);
$cir2 = rand(1,5);
$cir3 = rand(1,5);
$cir4 = rand(1,5);
$cir5 = rand(1,5);
//we now need to check to make sure it is not equal to any other value so we do not have repetitive circles
//cir1
while ($cir1 == $cir2) {
$cir2 = rand(1,5);
}
while ($cir1 == $cir3) {
$cir3 = rand(1,5);
}
while ($cir1 == $cir4) {
$cir4 = rand(1,5);
}
while ($cir1 == $cir5) {
$cir5 = rand(1,5);
}
//cir2
while ($cir2 == $cir1) {
$cir1 = rand(1,5);
}
while ($cir2 == $cir3) {
$cir3 = rand(1,5);
}
while ($cir2 == $cir4) {
$cir4 = rand(1,5);
}
while ($cir2 == $cir5) {
$cir5 = rand(1,5);
}
//cir3
while ($cir3 == $cir1) {
$cir1 = rand(1,5);
}
while ($cir3 == $cir2) {
$cir2 = rand(1,5);
}
while ($cir3 == $cir4) {
$cir4 = rand(1,5);
}
while ($cir3 == $cir5) {
$cir5 = rand(1,5);
}
//cir4
while ($cir4 == $cir1) {
$cir1 = rand(1,5);
}
while ($cir4 == $cir2) {
$cir2 = rand(1,5);
}
while ($cir4 == $cir3) {
$cir3 = rand(1,5);
}
while ($cir4 == $cir5) {
$cir5 = rand(1,5);
}
//cir5
while ($cir5 == $cir1) {
$cir1 = rand(1,5);
}
while ($cir5 == $cir2) {
$cir2 = rand(1,5);
}
while ($cir5 == $cir3) {
$cir3 = rand(1,5);
}
while ($cir5 == $cir4) {
$cir4 = rand(1,5);
}
//there might be a better way but i just did this quick
//now we must assign the values of 1-4 to the source of an image

//cir1
if ($cir1 == 1){
$cir1 = 'parishoners.png';
}
if ($cir1 == 2){
$cir1 = 'alterboys.png';
}
if ($cir1 == 3){
$cir1 = 'girls.png';
}
if ($cir1 == 4){
$cir1 = 'women.png';
}
if ($cir1 == 5){
$cir1 = 'father.png';
}
//cir2
if ($cir2 == 1){
$cir2 = 'parishoners.png';
}
if ($cir2 == 2){
$cir2 = 'alterboys.png';
}
if ($cir2 == 3){
$cir2 = 'girls.png';
}
if ($cir2 == 4){
$cir2 = 'women.png';
}
if ($cir2 == 5){
$cir2 = 'father.png';
}
//cir3
if ($cir3 == 1){
$cir3 = 'parishoners.png';
}
if ($cir3 == 2){
$cir3 = 'alterboys.png';
}
if ($cir3 == 3){
$cir3 = 'girls.png';
}
if ($cir3 == 4){
$cir3 = 'women.png';
}
if ($cir3 == 5){
$cir3 = 'father.png';
}
//cir4
if ($cir4 == 1){
$cir4 = 'parishoners.png';
}
if ($cir4 == 2){
$cir4 = 'alterboys.png';
}
if ($cir4 == 3){
$cir4 = 'girls.png';
}
if ($cir4 == 4){
$cir4 = 'women.png';
}
if ($cir4 == 5){
$cir4 = 'father.png';
}
//cir45
if ($cir5 == 1){
$cir5 = 'parishoners.png';
}
if ($cir5 == 2){
$cir5 = 'alterboys.png';
}
if ($cir5 == 3){
$cir5 = 'girls.png';
}
if ($cir5 == 4){
$cir5 = 'women.png';
}
if ($cir5 == 5){
$cir5 = 'father.png';
}
?>
<html>
<head>
<title>St. Francis of Assisi Parish&School</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="http://stfoa.org/inc/style.css" rel="stylesheet" type="text/css" media="screen" />
</head>

<body>


<!-- BEGIN CONTENT -->

<p><img src="http://stfoa.org/images/pics/home/main.jpg" width="580" height="279"></p>
<div align="right"></div>
<div id="Layer1" style="position:absolute; left:40px; top:160px; width:110px; height:110px"><img src="<?php print $cir1;?>" width="110" height="110"></div>
<div id="Layer2" style="position:absolute; left:170px; top:190px; width:110px; height:110px"><img src="<?php print $cir2;?>" width="110" height="110"></div>
<div id="Layer3" style="position:absolute; left:300px; top:200px; width:110px; height:110px"><img src="<?php print $cir3;?>" width="110" height="110"></div>
<div id="Layer4" style="position:absolute; left:410px; top:110px; width:110px; height:110px"><img src="<?php print $cir4;?>" width="110" height="110"></div>
<div id="Layer5" style="position:absolute; left:460px; top:0px; width:110px; height:110px"><img src="<?php print $cir5;?>" width="110" height="110"></div></body>

</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.