开发者

Shuffling two NSMutableArrays in a predictable manner

I have two NSMutableArrays of strings that I wish to combine and shuffle together. However, I want it so that every time it shuffles the original two arrays, it always yields the same array in the same order. How can this be done?

Could I seed some constant value into the random function like in C++ srand(constant) but in Objective-C?

Edit: Or say I just have one array (not sure if this makes any difference) and I wanted to shuffle that one array in a 开发者_JAVA百科predictable manner?


The way to do it is just to do srandom(constant) and use the random() function in Objective C. This way you'll always get the same shuffle and random values.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜