Lost Password?

  #1 (permalink)  
Old 08-26-2007, 02:07 PM
Paradine Paradine is offline
Learning Programmer
 
Join Date: Oct 2006
Posts: 48
Rep Power: 7
Paradine is on a distinguished road
Default Return random numbers without duplicates

I use this code to return random numbers without duplicates. I can't remember where I got it from but it isn't my code.

PHP Code:
//returns an array of random keys between 2 numbers
function &UniqueRands($min$max$keys){
    static 
$returnme = array();
    while(
in_array($x rand($min,$max),$returnme));
    
$returnme[] = $x;
    if(
$keys count($returnme)-&& $keys < ($max-$min))
        
UniqueRands($min$max$keys);
    return 
$returnme;

Usage:

PHP Code:
 //usage
$rands = & UniqueRands(0155); 
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
problem with large numbers saurav C and C++ 4 10-11-2007 04:52 PM
Generating Random Numbers with PHP Paradine PHP Tutorials 4 08-27-2007 07:09 PM
Random Generator of Unequal Numbers Paradine PHP Tutorials 0 08-26-2007 02:11 PM
A simple TicTacToe game Zunone C and C++ 1 08-16-2007 11:01 AM
null exception problem connor7777 C# Programming 2 03-28-2007 11:37 AM


All times are GMT -5. The time now is 03:50 PM.

Contest Stats

John ........ 223.00000
dargueta ........ 168.00000
Xav ........ 164.00000
gaylo565 ........ 18.00000
WingedPanther ........ 15.00000
|pH| ........ 15.00000
Johnnyboy ........ 3.00000
navghost ........ 1.00000

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 65%

Ads