Seed a random number : rand « stdlib.h « C Tutorial

Home
C Tutorial
1.Language
2.Data Type
3.String
4.printf scanf
5.Operator
6.Statement
7.Array
8.Function
9.Structure
10.Pointer
11.Memory
12.Preprocessor
13.File
14.Data Structure
15.Search Sort
16.Wide Character String
17.assert.h
18.ctype.h
19.math.h
20.setjmp.h
21.signal.h
22.stdio.h
23.stdlib.h
24.string.h
25.time.h
26.wctype.h
C / ANSI-C
C++
C++ Tutorial
Visual C++ .NET
C Tutorial » stdlib.h » rand 
23.24.2.Seed a random number
#include <stdio.h>
#include <stdlib.h>
 
int main(){
    int x;
 
    int seed = 11;
   
    srand(seed);

    puts("Behold! 100 Random Numbers!");

    for(x=0;x<100;x++){
        printf("%d \n", rand());
    }
    return(0);
}
Behold! 100 Random Numbers!
737120851
1813584622
279403949
1005612121
535583813
2076485441
1183398096
520913449
1154512877
1059637032
741048201
1735789551
1316165860
2091205829
608409849
2043917862
358495264
197486820
1978930740
19687262
608908788
411176766
946129446
727061997
2077503173
1575409043
653838784
1321679137
804509431
1206711916
1315236785
1501041106
2061242451
1959636594
472651030
1602552878
492843352
1968585005
378058371
436935333
712273104
364281872
1606570689
1874954196
490475024
696747194
166772383
1367120714
1112737848
32333121
691207997
793647892
340950235
741361510
935019051
427446745
1514759277
1430185376
528113855
855007105
1319659740
1198466770
1992406528
1702459445
1442334882
1720821640
1129825415
1058388889
1258471118
1660062129
1225867189
1550593068
279245380
1224789394
641368484
878709921
1064686765
1555571968
9653544
839812884
1548263274
2015299471
1313206600
821952515
1312932582
446790851
1064401295
655545570
1543054014
1175887620
944409743
1725662249
463822590
16861250
446033920
907172554
1167012078
103393064
633888716
881115352
23.24.rand
23.24.1.rand
23.24.2.Seed a random number
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.