Jump to content


Photo

Random Image


  • Please log in to reply
2 replies to this topic

#1 radons

radons
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 30 March 2006 - 04:20 PM

Hi, i was hoping someone could help me out...

I want to make a random image displayer that displays an random image.. That's not the problem though, the problem is that i want to give all the images have a pick chance. It will only show one image and must always show one.

So, one image has a pick chance of 40%, the other of 70% and so on.

I have no idea how to do this, thanks for your help =)

#2 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 30 March 2006 - 05:14 PM

i think u ment 40% and 60% otherwiseit would be over 100% but heres a lil sumet that will work

<?php
$images=file('randimages.txt');
$count=count($images);
$random=rand(0,$count);
echo $images[$random];
?>
and then in the file randimages.txt put 6 of the image you want at 60% and 4 of the image name that you want to be 40% seporate by line..
like this:

image60.jpg
image40.jpg
image60.jpg
image60.jpg
image40.jpg
image40.jpg
image60.jpg
image40.jpg
image60.jpg
image60.jpg

and then use $images[$random] to display the image name inside the image tags..
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

#3 radons

radons
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 30 March 2006 - 05:50 PM

Thanks for the reply.

But an example of what i have now:

All images are stored in the database,

ID LINK CHANCE
1 image1.jpg 40%
2 image2.jpg 50%
3 image3.jpg 10%

I want it to pick one and the ones with a higher chance well get picked faster.


Also, i'm working on another system that shows random images. Which all have their own chance to be showed, but it is random if it will show up or not.

ID LINK CHANCE (to be shown)
1 image1.jpg 40%
2 image2.jpg 50%
3 image3.jpg 60%
4 image4.jpg 70%
5 image5.jpg 30%

Think about an RPG with an item drop system, something like that here.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users