• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 301
  • Last Modified:

randomized

generate 100 unique (just one time only) integer random numbers between 1000 and 10000 in an array rn[100]. How many of these numbers fall between 4000 and 7000?
0
samuelccs
Asked:
samuelccs
  • 4
  • 2
  • 2
  • +3
1 Solution
 
ozoCommented:
Is this a homework assignment?
0
 
scrapdogCommented:
Post the code you have so far.
0
 
aj1070798Commented:
Since I am the one who set this question in class I will be very interested to see the answer.

Have fun folks!
0
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

 
rsongylCommented:
Can be done easily. You want the short way or the long way?
The long way is set all the number with counters and if anything hits 2, reset it.
The short way?? Press F1 if you need help. I think they have online help services.


0
 
scrapdogCommented:
Well, now that you're already in trouble with your teacher, it couldn't get any worse!!

for(i=0;i<9000;i++) x[i]=i+1000;
for(i=0;i<100;i++) { r=random(9000); t=x[i]; x[i]=x[r]; x[r]=t; }
for(i=0;i<100;i++) { if((x[i]>=4000)&&(x[i]<=7000)) n++; }
0
 
tatoCommented:

for(between=i=0;i<100;i++) if (array[i]>=4000 & array <=7000) between++;

printf("between 4000 and 7000 = %d",between);

0
 
scrapdogCommented:
Tato:  please do not post as an answer something somebody else already posted as a comment.
0
 
ozoCommented:
especially when it's incorrect
0
 
scrapdogCommented:
I know that my code did not meet samuelccs's specifications *exactly*...my intention was for a general "hint".
0
 
viktornetCommented:
OK, guys, here is my code... Maybe not the best, but who cares....

#include <iostream.h>
#include <conio.h>
#include <stdlib.h>

int main()
{
      int array[100];
      int ran, n = 0;
      bool dup;

      randomize();
      for (int i = 0; i < 100; i++) {
            dup = FALSE;
            ran = random(9000) + 1001;
            for (int j = 0; j <= i; j++) {
                  if (array[j] == ran)
                        dup = TRUE;
            }
            if (!dup) {
                                      array[i] = ran;
                                                      cout << array[i] << ' ';
                  if (array[i] >= 4000 && array[i] <= 7000) n++;
            } else i--;
      }
      cout << "\n\nThere were " << n << " in the range of 4000 and 7000";
      return 0;
}
0
 
viktornetCommented:
Oppps....

THis line

cout << "\n\nThere were " << n << " in the range of 4000 and 7000";

should have been

cout << "\n\nThere were " << n << " numbers in the range of 4000 and 7000";
0

Featured Post

Prepare for an Exciting Career in Cybersecurity

Help prevent cyber-threats and provide solutions to safeguard our global digital economy. Earn your MS in Cybersecurity. WGU’s MSCSIA degree program curriculum features two internationally recognized certifications from the EC-Council at no additional time or cost.

  • 4
  • 2
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now