def test_rand(self):
    src = '#include <stdlib.h>\n#include <stdio.h>\n#include <assert.h>\nint main()\n{\n    // we need RAND_MAX to be a bitmask (power of 2 minus 1). this assertions guarantees\n    // if RAND_MAX changes the test failure will focus attention on that issue here.\n    assert(RAND_MAX == 0x7fffffff);\n\n    srand(0xdeadbeef);\n    for(int i = 0; i < 10; ++i)\n        printf("%d\\n", rand());\n\n    unsigned int seed = 0xdeadbeef;\n    for(int i = 0; i < 10; ++i)\n        printf("%d\\n", rand_r(&seed));\n\n    bool haveEvenAndOdd = true;\n    for(int i = 1; i <= 30; ++i)\n    {\n        int mask = 1 << i;\n        if (mask > RAND_MAX) break;\n        bool haveEven = false;\n        bool haveOdd = false;\n        for(int j = 0; j < 1000 && (!haveEven || !haveOdd); ++j)\n        {\n            if ((rand() & mask) == 0)\n                haveEven = true;\n            else\n                haveOdd = true;\n        }\n        haveEvenAndOdd = haveEvenAndOdd && haveEven && haveOdd;\n    }\n    if (haveEvenAndOdd)\n        printf("Have even and odd!\\n");\n\n    return 0;\n}\n'
    expected = '490242850\n2074599277\n1480056542\n1912638067\n931112055\n2110392489\n2053422194\n1614832492\n216117595\n174823244\n760368382\n602359081\n1121118963\n1291018924\n1608306807\n352705809\n958258461\n1182561381\n114276303\n1481323674\nHave even and odd!\n'
    self.do_run(src, expected)
def test_rand(self):
    src = '#include <stdlib.h>\n#include <stdio.h>\n#include <assert.h>\nint main()\n{\n    // we need RAND_MAX to be a bitmask (power of 2 minus 1). this assertions guarantees\n    // if RAND_MAX changes the test failure will focus attention on that issue here.\n    assert(RAND_MAX == 0x7fffffff);\n\n    srand(0xdeadbeef);\n    for(int i = 0; i < 10; ++i)\n        printf("%d\\n", rand());\n\n    unsigned int seed = 0xdeadbeef;\n    for(int i = 0; i < 10; ++i)\n        printf("%d\\n", rand_r(&seed));\n\n    bool haveEvenAndOdd = true;\n    for(int i = 1; i <= 30; ++i)\n    {\n        int mask = 1 << i;\n        if (mask > RAND_MAX) break;\n        bool haveEven = false;\n        bool haveOdd = false;\n        for(int j = 0; j < 1000 && (!haveEven || !haveOdd); ++j)\n        {\n            if ((rand() & mask) == 0)\n                haveEven = true;\n            else\n                haveOdd = true;\n        }\n        haveEvenAndOdd = haveEvenAndOdd && haveEven && haveOdd;\n    }\n    if (haveEvenAndOdd)\n        printf("Have even and odd!\\n");\n\n    return 0;\n}\n'
    expected = '490242850\n2074599277\n1480056542\n1912638067\n931112055\n2110392489\n2053422194\n1614832492\n216117595\n174823244\n760368382\n602359081\n1121118963\n1291018924\n1608306807\n352705809\n958258461\n1182561381\n114276303\n1481323674\nHave even and odd!\n'
    self.do_run(src, expected)