Lost Password?

Go Back   CodeCall Programming Forum > Software Development > Tutorials > PHP Tutorials

Unregistered, Check out the Coder Battles in the Announcement and Game forums.

PHP Tutorials PHP Tutorials

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-26-2007, 02:11 PM
Paradine Paradine is offline
Learning Programmer
 
Join Date: Oct 2006
Posts: 48
Credits: 0
Rep Power: 8
Paradine is on a distinguished road
Default Random Generator of Unequal Numbers

This function returns numbers that are not equal meaning multiple values that do not equal the same:

PHP Code:
<?php
function randiff($min$max$num) {
    if (
$min<$max && $max-$min+>= $num && $num>0) {
        
$random_nums = array();
        
$i=0;
        while(
$i<$num) {
            
$rand_num rand($min$max);
            if (!
in_array($rand_num$random_nums)) {
                
$random_nums[] = $rand_num;
                
$i++;
            }
        }
        return 
$random_nums;
    } else {
        return 
false;
    }
}
?>
Usage:

PHP Code:
<?php
$nums 
randiff(0,10,2);
$var1 $nums[0];
$var2 $nums[1];
?>
</span>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Generating Random Numbers with PHP Paradine PHP Tutorials 4 08-27-2007 07:09 PM
Return random numbers without duplicates Paradine PHP Tutorials 0 08-26-2007 02:07 PM
How do I program a random generator? eddiewillers General Programming 4 07-24-2007 02:26 PM
Code:PHP Random Functions John PHP Tutorials 2 12-03-2006 10:04 AM
I need to generate a random number in PHP dirkfirst PHP Forum 7 07-05-2006 09:58 PM


All times are GMT -5. The time now is 03:22 AM.

Contest Stats

Xav ........ 1276.19
MeTh0Dz|Reb0rn ........ 1048.58
morefood2001 ........ 879.43
John ........ 872.39
marwex89 ........ 869.98
WingedPanther ........ 761.06
Brandon W ........ 684.87
chili5 ........ 294.12
Steve.L ........ 216.18
dargueta ........ 192.86

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 81%

Ads