IT Community - Software Programming, Web Development and Technical Support

Avoid dublicate in rand()

This is a discussion on Avoid dublicate in rand() within the PHP Programming forums, part of the Web Development category; Hi all, How we avoid the duplicate value during random number generation without using unique function...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > PHP Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 11-29-2007, 12:10 AM
Vani Sri Vani Sri is offline
D-Web Trainee
 
Join Date: Aug 2007
Posts: 33
Vani Sri is on a distinguished road
Default Avoid dublicate in rand()

Hi all,
How we avoid the duplicate value during random number generation without using unique function
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 11-29-2007, 01:57 AM
velhari velhari is offline
D-Web Programmer
 
Join Date: Mar 2007
Location: Chennai
Posts: 67
velhari is on a distinguished road
Send a message via AIM to velhari
Thumbs up Re: Avoid dublicate in rand()

Hi,
If suppose you want to get the random numbers from 1 to 5 without any duplicates means,

PHP Code:
while ( $i )
{
    
$rnd rand(1,5);
    if( !isset(
$tmprnd[$rnd]) )
    {
        
$tmprnd[$rnd] = 'set';
        echo 
$rnd."<br>";
        
$i++;
    }    

Hope it helps.
__________________
Regards,
VELHARI
I am not totally useless. I can be used for a bad example
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 11-29-2007, 02:27 AM
Vani Sri Vani Sri is offline
D-Web Trainee
 
Join Date: Aug 2007
Posts: 33
Vani Sri is on a distinguished road
Default Re: Avoid dublicate in rand()

Hi velhari,

Thank u very much. It's work fine.

Regards,
vani
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
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

vB 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
Prevention Measures to Avoid SQL Injection vadivelanshanmugam Database Support 0 01-31-2008 10:27 PM
How to avoid Sys.WebForms.PageRequestManagerTimeOutException while using Ajax? kingmaker C# Programming 1 07-22-2007 11:34 PM
What is meant by Bandwidth stealing..? how can we avoid it..? bluesky Server Management 1 07-19-2007 12:36 AM
Things To Avoid, Search Engine Optimization vadivelanvaidyanathan Search Engine Optimization 2 04-26-2007 08:59 AM
Search Engine Optimization -10 common mistakes to avoid spid4r Search Engine Optimization 0 03-09-2007 12:33 AM


All times are GMT -7. The time now is 03:47 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0