Mysidia Adoptables Support Forum  

Home Community Mys-Script Creative Off-Topic
Go Back   Mysidia Adoptables Support Forum > Mysidia Adoptables > Questions and Supports

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 09-29-2011, 06:06 PM
Hall of Famer's Avatar
Hall of Famer Hall of Famer is offline
Administrator, Lead Coder
 
Join Date: Dec 2008
Location: South Brunswick
Posts: 4,448
Gender: Male
Credits: 658,978
Hall of Famer is on a distinguished road
Default

Well the problem is that you are choosing two random values from the array input[], while the function array_rand() automatically sort the two generated values. The possible combinations from the array $rand_keys[] is:

PHP Code:
$rand_keys[0] = 3$rand_keys[1] = 4
$rand_keys
[0] = 3$rand_keys[1] = 5
$rand_keys
[0] = 3$rand_keys[1] = 6
$rand_keys
[0] = 4$rand_keys[1] = 5
$rand_keys
[0] = 4$rand_keys[1] = 6
$rand_keys
[0] = 5$rand_keys[1] = 
As you can see from the above 6 combinations, the first element $rand_keys[0] never contains 6, while the second element $rand_keys[1] never contains 3. If you print the first element to the screen, it has 1/2 chance to be 3, 1/3 chance to be 4, and 1/6 chance to be 5. This is why 5 appears in a much smaller chance than 3 and 4, while 6 never shows up. Hope this explanation is clear enough, I personally would not use the function array_rand() to generate more than one random numbers.

There are many ways to resolve this glitch. If you insist on working with array_rand() function, Id recommend you use PHP shuffle which destroys the orders in an array and randomize it. The instruction on how to use shuffle can be found from php's official site:
http://php.net/manual/en/function.shuffle.php
__________________


Mysidia Adoptables, a free and ever-improving script for aspiring adoptables/pets site.
Reply With Quote
Reply

Thread Tools
Display Modes

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Hall of Famer's PHP Tutorials: Chapter 6 - PHP Arrays Hall of Famer Tutorials and Tips 0 03-16-2013 07:14 PM
My MySQL? Rozel Questions and Supports 6 05-01-2011 08:53 AM
Mysql help? rickasawr Questions and Supports 5 04-26-2011 09:31 AM
MySQL: What to do? Knyfe Questions and Supports 18 03-11-2011 12:52 PM
mySQL help aroymart Questions and Supports 4 04-20-2009 12:13 AM


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

Currently Active Users: 10725 (0 members and 10725 guests)
Threads: 4,081, Posts: 32,032, Members: 2,016
Welcome to our newest members, jolob.
BETA





What's New?

What's Hot?

What's Popular?


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
vBCommerce I v2.0.0 Gold ©2010, PixelFX Studios
vBCredits I v2.0.0 Gold ©2010, PixelFX Studios
Emoticons by darkmoon3636