#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    2
    Rep Power
    0

    Can't figure out what's wrong with my Random Number Generator in C


    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    
    	#define MAX_VALUE = 6;
    	#define MIN_VALUE = 1;
    	const int NUMBER_OF_VALUES =(6 - 1 + 1);
    	const int NUMBER_OF_TRIALS = 1000;
    	
    	int main()
    	{
    		int count[NUMBER_OF_VALUES];
    		int i;
    		int value = i + MIN_VALUE;
    		for (i=0;i<NUMBER_OF_TRIALS;i++)
    		{
    			int position;
    			int random;
    			double randomReal;
    			randomReal = rand()/(((double)RAND_MAX)+1)) * NUMBER_OF_VALUES + MIN_VALUE;
    			random = (int)(randomReal);
    			position = random - MIN_VALUE;
    			count[position] = count[position]+1;
    		}
    		printf("Counts\n");
    		for (i=0;i<NUMBER_OF_VALUES;i++)
    		{
    			printf("%d : %d\n",(value), count[i]);
    		}
    		int expectedCount;
    		expectedCount = NUMBER_OF_TRIALS/NUMBER_OF_VALUES;
    		printf("The expected count is %d\n",expectedCount);
    		printf("Distance From Average\n");
    		for (i=0;i<NUMBER_OF_VALUES;i++)
    		{
    			int distanceFromExpected;
    			distanceFromExpected = count[i] - NUMBER_OF_TRIALS/NUMBER_OF_VALUES;
    			printf("%d : %d\n",(value),abs(distanceFromExpected));
    		}
    	}
    Every time I try to run it, I get these errors:

    Code:
    **** Build of configuration Release for project RandomNumberCheckerInC ****
    
    make all 
    Building target: RandomNumberCheckerInC
    Invoking: GCC C Linker
    gcc  -o"RandomNumberCheckerInC"  ./randomNumberChecker.o   
    /usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 0 has invalid symbol index 11
    /usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 1 has invalid symbol index 12
    /usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 2 has invalid symbol index 2
    /usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 3 has invalid symbol index 2
    /usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 4 has invalid symbol index 11
    /usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 5 has invalid symbol index 13
    /usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 6 has invalid symbol index 13
    /usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 7 has invalid symbol index 13
    /usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 8 has invalid symbol index 2
    /usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 9 has invalid symbol index 2
    /usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 10 has invalid symbol index 12
    /usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 11 has invalid symbol index 13
    /usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 12 has invalid symbol index 13
    /usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 13 has invalid symbol index 13
    /usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 14 has invalid symbol index 13
    /usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 15 has invalid symbol index 13
    /usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 16 has invalid symbol index 13
    /usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 17 has invalid symbol index 13
    /usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 18 has invalid symbol index 13
    /usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 19 has invalid symbol index 13
    /usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 20 has invalid symbol index 20
    /usr/lib/gcc/x86_64-linux-gnu/4.4.3/../../../../lib/crt1.o: In function `_start':
    (.text+0x20): undefined reference to `main'
    collect2: ld returned 1 exit status
    make: *** [RandomNumberCheckerInC] Error 1
    Which I figure to mean that there's no main method but I clearly have a main method in my program. I'm just a beginner C programmer using Eclipse to build and run my code. Why won't my current code work correctly?
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,379
    Rep Power
    1871
    Well it doesn't even compile, so forget about linker error messages for the moment.

    > #define MAX_VALUE = 6;
    > #define MIN_VALUE = 1;

    Change this to either
    #define MAX_VALUE 6
    #define MIN_VALUE 1

    or this
    const int MAX_VALUE = 6;
    const int MIN_VALUE = 1;

    EDIT
    Nevermind, it's over here as well (another wasted post)
    http://cboard.cprogramming.com/c-pro...ml#post1176767
    Last edited by salem; September 9th, 2013 at 01:07 AM.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper

IMN logo majestic logo threadwatch logo seochat tools logo