LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-21-2006, 06:22 AM   #1
icylicious
LQ Newbie
 
Registered: Jul 2006
Posts: 12

Rep: Reputation: 0
i found a way to random generate 4 unique numbrs but prob is sometimes it doesn't run


i found a way to random generate 4 unique numbrs but prob is sometimes it doesn't run.. pls help me what are tne necessary changes i should do. here's the code i did:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

void rep(int *, int*, int*,int*);

int main(void)
{
int i, n=4, a, b,c,d;

srand(time(NULL));
for (i=0; i < n; ++i) {

a= rand() % 10;
b= rand() % 10;
c= rand()%10;
d= rand()%10;
};
rep(&a,&b,&c,&d);
return 0;
}

void rep(int*a, int*b,int*c,int*d)
{
int tmp;
if (*a !=*b)
{tmp = *b;
*b = tmp;
{if(*a!=*c)
{if(*b!=*c)
{if(*a!=*d)
{if(*b!=*d)
{if(*c!=*d)
printf("%d %d %d %d\n",*a,*b,*c,*d);} } } } }
return;
}
else
main();

}
 
Old 08-21-2006, 06:35 AM   #2
cupubboy
Member
 
Registered: May 2003
Location: Bucharest,Romania
Distribution: Fedora Core 7
Posts: 109

Rep: Reputation: 15
I think you already have a thread about this .. could have at least just bumped that

I think you should use code tags

I think you should explain what "sometimes it doesn't run" means

I think that's all .. cheers
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
pls help on how i can generate 4 digit random number that are unique within the set icylicious Programming 7 08-22-2006 01:00 PM
Found a random linux box at work... what distro is it running?? fatrandy13 Linux - General 2 06-14-2006 07:45 PM
Generate random number with C++ TruongAn Programming 5 11-09-2005 12:01 AM
can bash generate random digit? sorno Linux - Newbie 5 08-17-2005 06:05 AM
Python problems trying to generate a random number davholla Programming 0 10-27-2003 04:07 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:51 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration