Q:

Why does my sorted array occasionally return random 0s at the end?

I wrote a program to sort a randomly generated array of 50 integers from greatest to least. So far it works, but it will occasionally return random zeros at the end of the sorted array. These zeros are not present in the unsorted array, and they do not always appear. Here's my program:
#import <Foundation/Foundation.h>

@interface Number: NSObject

- (void) start;
- (int) getValue;
- (void) counted;
- (void) placeValue: (int) a;

@end

@implementation Number
{
    int x;
}

- (void) start
{
    x = arc4random_uniform(1000);
    if (x == 1)
    {
        x = x+1;
    }
}

- (int) getValue
{
    return x;
}

- (void) counted
{
    x = 0;
}

- (void) placeValue: (int) a
{
    x = a;
}

@end

int main(int argc, const char * argv[])
{

    @autoreleasepool
    {
        NSMutableArray *unsortedArray = [[NSMutableArray alloc] initWithCapacity: 50];

        for (int n = 0; n < 50; n++)
        {
            Number *num = [[Number alloc] init];
            [num start];
            [unsortedArray addObject: num];
        }

        for  (int n = 0; n < 50; n++)
        {
            printf("%i, ", [unsortedArray[n] getValue]);
        }
        printf ("unsorted array.\n\n");

        int x = 0;
        int y = 1001;

        for (int n = 0; n < 50; n++)
        {
            for (int m = 0; m < 50; m++)
            {
                if (([unsortedArray[m] getValue] > x) && ([unsortedArray[m] getValue] < y))
                {
                    x = [unsortedArray[m] getValue];
                }
            }

            printf("%i, ", x);
            y = x;
            x = 0;
        }

        printf("sorted array.\n");
    } return 0;
}

A:

Try this:
- (void)start
{
    x = (arc4random_uniform(1000) + 1);
}

You don't want to only be increasing x when you hit 0 or 1, since that will skew the results. arc4random_uniform will return a random number less than 1000 in this case, so 0 -> 999, adding 1 to all values, gives you 1 -> 1000. Adjust your numbers to suit what you need.
There are other issues in your code though. Why create your own Number class? Why create your own sort method? Use NSNumber and NSArray's sort methods.
Here is a much cleaner version:
int main(int argc, const char * argv[])
{
    @autoreleasepool
    {
        NSMutableArray* unsortedArray = [[NSMutableArray alloc] initWithCapacity:50];

        for (NSUInteger n = 0; n < 50; ++n) {
            [unsortedArray addObject:@(arc4random_uniform(999) + 1)];
        }

        for (NSUInteger n = 0; n < 50; ++n) {
            printf("%li, ", (long)[unsortedArray[n] integerValue]);
        }
        printf ("unsorted array.\n\n");

        NSArray* sortedArray = [unsortedArray sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
            return [obj2 compare:obj1];
        }];

        for (NSUInteger n = 0; n < 50; ++n) {
            printf("%li, ", (long)[sortedArray[n] integerValue]);
        }
        printf("sorted array.\n");
    } 

    return 0;
}

