颜色(数字)随机 -- 不重复

+ (NSArray *)randomColors {

//    NSMutableArray *startColors = [NSMutableArray arrayWithObjects:randomColor1,randomColor2,randomColor3,randomColor4,randomColor5,randomColor6,randomColor7,randomColor8,randomColor9,randomColor0,nil];

    NSMutableArray *startColors = [NSMutableArray arrayWithObjects:@0,@1,@2,@3,@4,@5,@6,@7,@8,@9,nil];

    

    NSMutableArray *colors = [NSMutableArray arrayWithObjects:@0,@0,@0,@0,@0, nil];

    for (int i = 0; i < 5; i++) {

        int t = arc4random()%startColors.count;

        colors[i] = startColors[t];

        startColors[t] = [startColors lastObject];

        [startColors removeLastObject];

    }

    return colors;

}

posted @ 2015-04-16 11:49  softlit  阅读(463)  评论(0编辑  收藏  举报