ninjawesome222's Profile User Rating: -----

Reputation: 1 Apprentice
Active Members
Active Posts:
106 (0.05 per day)
27-January 10
Profile Views:
Last Active:
User is offline Feb 12 2014 05:54 PM

Previous Fields

Dream Kudos:

Latest Visitors

Icon   ninjawesome222 has not set their status

Posts I've Made

  1. In Topic: Generate Unique Numbers in C

    Posted 12 Feb 2014

    I am having difficulty generating random numbers that are unique. What I have attempted to do is generate a random number, store it in an array, and then when I generate the next random number, I check each slot of the array for duplicates. However, when I run this code, it still yields duplicates and sometimes there is not output at all. Any help is greatly appreciated.

    Here is my code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    int main (void) {
    	int limit = 4;
    	int students = 5;
    	int exams[4];
    	int class[5] = {1,2,3,4,5};
    	int random;
    	int i, j;
    	int flag = -1;
    	for (i = 0; i < limit; i++) {
    		flag = 1;
    		random = rand() % students;
    		do {
    		for (j = 0; j < limit; j++) {
    			if (class[random] == exams[random]) {
    				j = 0;
    				flag = -1;
    				random = rand() % students;
    			} while (flag == -1);
    			exams[i] = class[random];
    	for (i = 0; i < 4; i++) {
    		printf("%d ", exams[i]);
    	return 0;
  2. In Topic: Generate Unique Numbers in C

    Posted 12 Feb 2014

    View PostCTphpnwb, on 11 February 2014 - 07:05 PM, said:

    Question about your "correct" output: How do you know what student took each exam, and therefore that the student grading it isn't grading their own exam?

    Perhaps my description was not clear enough, my apologies. When the output says student 1 will grade exams 4, 3, 2, and 5, I mean he will be grading student 4's exam, student 3's exam, student 2's exam, and student 5's exam.

My Information

Member Title:
D.I.C Head
Age Unknown
Birthday Unknown

Contact Information



ninjawesome222 hasn't added any friends yet.


ninjawesome222 has no profile comments yet. Why not say hello?