Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
既知のデータ セット (n=35) から 6 つのサンプルを 10,000 回ランダムに選択しようとしています。これは基本的なコードのように感じますが、見つかりません。
助言がありますか?
iOS では、次のことができます。
#include <stdlib.h> - (id)randomElement:(NSArray *)array { NSInteger index = arc4random() % array.count; return [array objectAtIndex:index]; }
arc4random は、疑似乱数の均一な分布を約束します。これは、パラメータをドロップする配列のカテゴリ メソッドにすることもできます。