fork download
  1. //#include <ansi_c.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <time.h>
  5.  
  6. int randomGenerator(int min, int max);
  7. int NotUsedRecently (int number);
  8.  
  9. int main(void)
  10. {
  11. int i=0;
  12. for(i=0;i<1000;i++)
  13. {
  14. printf("%d, ", randomGenerator(0, 32767));
  15. if(i%20 == 0) printf("\n");
  16. }
  17. return 0;
  18. }
  19.  
  20. //will generate pseudo random numbers between min and max
  21. int randomGenerator(int min, int max)
  22. {
  23. int random, trying;
  24.  
  25. trying = 1;
  26. while(trying)
  27. {
  28. random = (rand()/32767.0)*(max+1);
  29. ((random >= min) && NotUsedRecently(random)) ? (trying = 0) : (trying = 1);
  30. }
  31.  
  32. return random;
  33. }
  34.  
  35. //written for depth of 64most recent numbers.
  36. int NotUsedRecently (int number)
  37. {
  38. static int recent[64];//change this array size as needed
  39. int i,j;
  40. int notUsed = 1;
  41.  
  42. for(i=0;i<(sizeof(recent)/sizeof(recent[0]));i++)
  43. (number != recent[i]) ? (notUsed==notUsed) : (notUsed=0, i=(sizeof(recent)/sizeof(recent[0])));
  44. if(notUsed)
  45. {
  46. for(j=(sizeof(recent)/sizeof(recent[0]));j>1;j--)
  47. {
  48. recent[j-1] = recent[j-2];
  49. }
  50. recent[j-1] = number;
  51. }
  52. return notUsed;
  53. }
  54.  
Time limit exceeded #stdin #stdout 5s 2248KB
stdin
Standard input is empty
stdout
1804344447, 
595440430, 164370261, 1872912914, 1433237071, 2071615711, 1637369502, 135443008, 769175930, 1405515711, 964970116, 1604191526, 97861813, 1811009943, 1388551848, 931695038, 502882934, 1144771012, 703166720, 273656381, 910986799, 
475399489, 1113176532, 673498789, 241557389, 880584707, 1519076124, 1087828990, 649456006, 197391618, 840095766, 1480233867, 2120203676, 1682643761, 1249356046, 1879224863, 1451954524, 2077202893, 1653670983, 160071181, 1860867543, 
1426338869, 989412487, 1626322454, 115202829, 758726291, 1392995848, 2019464833, 523182879, 1159696752, 1796157805, 289797213, 1997884113, 496207704, 1132359449, 1762458574, 1328577043, 1966649994, 1523925184, 1091950827, 655087619, 
1297049339, 1935883004, 1497504729, 1072227546, 1707301417, 1268448682, 1903096477, 1473992159, 2109011213, 1675953592, 156578325, 1874382126, 1430889318, 998760425, 565943655, 127023256, 776613035, 340756887, 971538887, 1618852435, 
1175868425, 741633034, 1381309640, 2012878716, 1575463820, 1138725074, 1768525923, 270225093, 1968103944, 479129591, 34927546, 677761734, 1315188040, 878598193, 445209396, 11938969, 1719101566, 1296614177, 1923489238, 1484587732, 
2119042327, 615861257, 1247015366, 821247815, 382929063, 2103053082, 580543642, 145403488, 787798629, 356065605, 984241721, 1624470125, 107527686, 1824982220, 317923146, 2026526537, 526892261, 86358807, 725290070, 288393486, 
1992681603, 1567304927, 1121294842, 1771427683, 1323751675, 891926481, 448979688, 1100377958, 659999862, 1300381576, 859463700, 1506734749, 1064512402, 631029757, 203815527, 836565354, 398727925, 2115563299, 1672533551, 156860922, 
800374069, 1439906012, 2076160556, 569312931, 122731983, 1847041001, 1412514165, 2049000916, 1611546433, 1172523132, 1815075021, 302920623, 944257708, 1595417647, 75119345, 1782464427, 1347335264, 911737395, 473667304, 45019732, 
681752105, 1314059976, 875089983, 1522796714, 1074801061, 1720039847, 209507403, 843872076, 407240585, 1051999976, 1686052297, 176233663, 1891512876, 373977225, 2094344477, 1655969463, 1210837474, 788452649, 1422051761, 993368108, 
556673227, 116496065, 1824565633, 1392211333, 2025687391, 1595384277, 1153612359, 1797147234, 1360330009, 2004996721, 1565167607, 66785225, 700380457, 259348339, 900266846, 469467928, 1096366581, 1736985685, 222959351, 861737495, 
419652404, 2137873627, 1700413340, 1271290922, 1907262209, 392967692, 2116541151, 1678892821, 1240128692, 1883002645, 372640932, 2083411667, 1647197724, 1204108232, 1844108915, 336167397, 2042800894, 1624854277, 1176556075, 1822909087, 
305877581, 948773144, 499205014, 62737780, 710638808, 1344890113, 907450211, 471028714, 35526106, 677221760, 242990556, 878039500, 1520259298, 1086178837, 647506196, 1283839321, 1921120384, 1487990498, 1052048249, 1688870033, 
176535891, 814518981, 379793320, 1025931161, 595644239, 151947587, 1873128703, 354535140, 997407768, 1633435481, 113201787, 762991698, 1386987494, 952138316, 1587714036, 92808051, 722337370, 1365712365, 2001098320, 1564986826, 
1124393255, 698686704, 256297439, 900517493, 1541094925, 1098536964, 663906960, 1301892411, 1945731084, 1512434091, 1072758053, 630990574, 195305794, 1913994952, 394879916, 2119612527, 1671995165, 168452409, 1866599474, 1429558134, 
2071194286, 1646046718, 134974971, 773351037, 337562525, 2052185086, 1601912676, 104382713, 1820931268, 1377278634, 2014524511, 1580490436, 66325503, 1802014824, 274872129, 922380281, 477645534, 1109678279, 1750207999, 242177012, 
1961654898, 455569067, 1086677277, 1722913338, 214692818, 857884231, 1495073919, 2139134936, 1681126701, 185415817, 818973035, 378062373, 1019390157, 588737022, 1219828743, 784748866, 1421519298, 988188002, 1621444541, 133116315, 
758687298, 1403686263, 971896876, 524357073, 92769431, 1803613986, 1361211964, 2005499700, 487787144, 1128452237, 689786577, 257035149, 1974885645, 461850558, 22126390, 1729442111, 229385521, 861559991, 1503893046, 1074365318, 
1703374965, 1266937127, 1911460944, 398985808, 1035602135, 606549623, 168186090, 804125791, 370886402, 2087886346, 1647417542, 135331217, 766625209, 1409352