•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 397,589 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,018 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser:
Views: 2406 | Replies: 4
![]() |
•
•
Join Date: Jul 2005
Posts: 4
Reputation:
Rep Power: 0
Solved Threads: 0
hi
i want to generate non repeated random numbers many times. for that i m using the following code.
<< moderator edit: added [code][/code] tags >>
it generates random numbers from 0 to 20 without repeating in an array. but it generates only once. next time in the for loop ( in j ) it gives the same pattern again , which i dont want. can some body please help me to get different pattern every time in the for loop ( for j ).
i want to generate non repeated random numbers many times. for that i m using the following code.
#include "sys/types.h"
#include "stdio.h"
#define MAX 200
#define N 20
main()
{
int array[N],r;
int n = 0; int count_check,count_gen ,i,j;
for(j=0;j<10;j++,printf("\n"))
{
srand(j);
for (count_gen=0;count_gen<=MAX;count_gen++)
{
r = rand()%N;
for ( count_check = 0; count_check < n; count_check++ )
{
if ( r == array[count_check] )break;
}// end for count_check.
if ( count_check == n ) array[n++] = r;
}// end for count_gen.
for(i=0;i<N;i++)
printf("%d\n",array[i]);
}// end for j.
}// end of main.it generates random numbers from 0 to 20 without repeating in an array. but it generates only once. next time in the for loop ( in j ) it gives the same pattern again , which i dont want. can some body please help me to get different pattern every time in the for loop ( for j ).
•
•
Join Date: Nov 2004
Location: Tucson, Az
Posts: 107
Reputation:
Rep Power: 4
Solved Threads: 2
Read this on random numbers http://www.eternallyconfuzzled.com/tuts/random.html
Join me on IRC:
Server: irc.daniweb.com
Channel: #C++
Chat Via:
http://daniweb.com/chat/minichat.php
or
Your favorite IRC client.
Server: irc.daniweb.com
Channel: #C++
Chat Via:
http://daniweb.com/chat/minichat.php
or
Your favorite IRC client.
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb C Marketplace
Similar Threads
- Random Numbers on button (Java)
- C++ Random Numbers (C++)
- Program will not generate random numbers (C++)
- need help, need to generate 10 random numbers, such that their sum is less than 1 (C)
- random numbers all different??? (C++)
Other Threads in the C Forum
- Previous Thread: recursion and for loop to recursion
- Next Thread: Sane way of dynamically allocating arrays beyond declaration.



Linear Mode