Jump to content

Random Image


radons

Recommended Posts

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 =)
Link to comment
https://forums.phpfreaks.com/topic/6185-random-image/
Share on other sites

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

[code]
<?php
$images=file('randimages.txt');
$count=count($images);
$random=rand(0,$count);
echo $images[$random];
?>
[/code]
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..
Link to comment
https://forums.phpfreaks.com/topic/6185-random-image/#findComment-22348
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/6185-random-image/#findComment-22354
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.