challenge シードを固定した乱数

シードを固定した疑似乱数を出力してください。
数回実行して、常に同じ結果が出力されることを確認してください。

Posted feedbacks - Objective-C

ガバレッジをあげる為と自分の勉強の為に投稿いたしました

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
#import <Foundation/Foundation.h>
#define SEED srand(64)

int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

    int r;
    SEED;
    for (int i = 0; i < 10; i++) {
        r = rand();
    }
    NSLog(@"%d",r);    
    [pool drain];
    return 0;
}

Index

Feed

Other

Link

Pathtraq

loading...