{
    "content": [
        {
            "type": "text",
            "text": "# Math::Random::ISAAC (perldoc)\n\n## NAME\n\nMath::Random::ISAAC - Perl interface to the ISAAC PRNG algorithm\n\n## SYNOPSIS\n\nuse Math::Random::ISAAC;\nmy $rng = Math::Random::ISAAC->new(@seeds);\nfor (0..30) {\nprint 'Result: ' . $rng->irand() . \"\\n\";\n}\n\n## DESCRIPTION\n\nAs with other Pseudo-Random Number Generator (PRNG) algorithms like the Mersenne Twister (see\nMath::Random::MT), this algorithm is designed to take some seed information and produce\nseemingly random results as output.\n\n## Sections\n\n- **NAME**\n- **VERSION**\n- **SYNOPSIS**\n- **DESCRIPTION**\n- **METHODS**\n- **PURPOSE**\n- **ACKNOWLEDGEMENTS**\n- **SEE ALSO**\n- **CAVEATS**\n- **BUGS**\n- **AUTHOR**\n- **COPYRIGHT AND LICENSE**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "Math::Random::ISAAC",
        "section": "",
        "mode": "perldoc",
        "summary": "Math::Random::ISAAC - Perl interface to the ISAAC PRNG algorithm",
        "synopsis": "use Math::Random::ISAAC;\nmy $rng = Math::Random::ISAAC->new(@seeds);\nfor (0..30) {\nprint 'Result: ' . $rng->irand() . \"\\n\";\n}",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "VERSION",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 8,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 51,
                "subsections": []
            },
            {
                "name": "METHODS",
                "lines": 41,
                "subsections": []
            },
            {
                "name": "PURPOSE",
                "lines": 16,
                "subsections": []
            },
            {
                "name": "ACKNOWLEDGEMENTS",
                "lines": 7,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 15,
                "subsections": []
            },
            {
                "name": "CAVEATS",
                "lines": 14,
                "subsections": []
            },
            {
                "name": "BUGS",
                "lines": 6,
                "subsections": []
            },
            {
                "name": "AUTHOR",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "COPYRIGHT AND LICENSE",
                "lines": 14,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "Math::Random::ISAAC - Perl interface to the ISAAC PRNG algorithm\n",
                "subsections": []
            },
            "VERSION": {
                "content": "version 1.004\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "use Math::Random::ISAAC;\n\nmy $rng = Math::Random::ISAAC->new(@seeds);\n\nfor (0..30) {\nprint 'Result: ' . $rng->irand() . \"\\n\";\n}\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "As with other Pseudo-Random Number Generator (PRNG) algorithms like the Mersenne Twister (see\nMath::Random::MT), this algorithm is designed to take some seed information and produce\nseemingly random results as output.\n\nHowever, ISAAC (Indirection, Shift, Accumulate, Add, and Count) has different goals than these\ncommonly used algorithms. In particular, it's really fast - on average, it requires only 18.75\nmachine cycles to generate a 32-bit value. This makes it suitable for applications where a\nsignificant amount of random data needs to be produced quickly, such solving using the Monte\nCarlo method or for games.\n\nThe results are uniformly distributed, unbiased, and unpredictable unless you know the seed. The\nalgorithm was published by Bob Jenkins in the late 90s and despite the best efforts of many\nsecurity researchers, no feasible attacks have been found to date.\n\nUSAGE WARNING\nThere was no method supplied to provide the initial seed data by the author. On his web site,\nBob Jenkins writes:\n\nSeeding a random number generator is essentially the same problem as\nencrypting the seed with a block cipher.\n\nIn the same spirit, by default, this module does not seed the algorithm at all -- it simply\nfills the state with zeroes -- if no seed is provided. The idea is to remind users that\nselecting good seed data for their purpose is important, and for the module to conveniently set\nit to something like \"localtime\" behind-the-scenes hurts users in the long run, since they don't\nunderstand the limitations of doing so.\n\nThe type of seed you might want to use depends entirely on the purpose of using this algorithm\nin your program in the first place. Here are some possible seeding methods:\n\n1 Math::TrulyRandom\nThe Math::TrulyRandom module provides a way of obtaining truly random data by using timing\ninterrupts. This is probably one of the better ways to seed the algorithm.\n\n2 /dev/random\nUsing the system random device is, in principle, the best idea, since it gathers entropy\nfrom various sources including interrupt timing, other device interrupts, etc. However, it's\nnot portable to anything other than Unix-like platforms, and might not produce good data on\nsome systems.\n\n3 localtime()\nThis works for basic things like simulations, but results in not-so-random output,\nespecially if you create new instances quickly (as the seeds would be the same within\nper-second resolution).\n\n4 Time::HiRes\nIn theory, using Time::HiRes is the same as option (2), but you get a higher resolution time\nso you're less likely to have the same seed twice. Note that you need to transform the\noutput into an integer somehow, perhaps by taking the least significant bits or using a hash\nfunction. This would be less prone to duplicate instances, but it's still not ideal.\n",
                "subsections": []
            },
            "METHODS": {
                "content": "new\nMath::Random::ISAAC->new( @seeds )\n\nCreates a \"Math::Random::ISAAC\" object, based upon either the optimized C/XS version of the\nalgorithm, Math::Random::ISAAC::XS, or falls back to the included Pure Perl module,\nMath::Random::ISAAC::PP.\n\nExample code:\n\nmy $rng = Math::Random::ISAAC->new(time);\n\nThis method will return an appropriate Math::Random::ISAAC object or throw an exception on\nerror.\n\nrand\n$rng->rand()\n\nReturns a random double-precision floating point number which is normalized between 0 and 1\n(inclusive; it's a closed interval).\n\nInternally, this simply takes the uniformly distributed unsigned integer from \"$rng->irand()\"\nand divides it by \"232-1\" (maximum unsigned integer size)\n\nExample code:\n\nmy $next = $rng->rand();\n\nThis method will return a double-precision floating point number or throw an exception on error.\n\nirand\n$rng->irand()\n\nReturns the next unsigned 32-bit random integer. It will return a value with a value such that:\n0 <= x <= 232-1.\n\nExample code:\n\nmy $next = $rng->irand();\n\nThis method will return a 32-bit unsigned integer or throw an exception on error.\n",
                "subsections": []
            },
            "PURPOSE": {
                "content": "The intent of this module is to provide single simple interface to the two compatible\nimplementations of this module, namely, Math::Random::ISAAC::XS and Math::Random::ISAAC::PP.\n\nIf, for some reason, you need to determine what version of the module is actually being included\nby \"Math::Random::ISAAC\", then:\n\nprint 'Backend type: ', $Math::Random::ISAAC::DRIVER, \"\\n\";\n\nIn order to force use of one or the other, simply load the appropriate module:\n\nuse Math::Random::ISAAC::XS;\nmy $rng = Math::Random::ISAAC::XS->new();\n# or\nuse Math::Random::ISAAC::PP;\nmy $rng = Math::Random::ISAAC::PP->new();\n",
                "subsections": []
            },
            "ACKNOWLEDGEMENTS": {
                "content": "*   Special thanks to Bob Jenkins <bobjenkins@burtleburtle.net> for devising this very clever\nalgorithm and releasing it into the public domain.\n\n*   Thanks to John L. Allen (contact unknown) for providing a Perl port of the original ISAAC\ncode, upon which \"Math::Random::ISAAC::PP\" is heavily based. His version is available on\nBob's web site, in the SEE ALSO section.\n",
                "subsections": []
            },
            "SEE ALSO": {
                "content": "Math::Random::ISAAC::XS, the C/XS optimized version of this module, which will be used\nautomatically if available.\n\n<http://burtleburtle.net/bob/rand/isaacafa.html>, Bob Jenkins' page about ISAAC, which explains\nthe algorithm as well as potential attacks.\n\n<http://eprint.iacr.org/2006/438.pdf>, a paper entitled \"On the pseudo-random generator ISAAC,\"\nwhich claims there are many seeds which will produce non-uniform results. The author,\nJean-Philippe Aumasson, argues ISAAC should be using rotations (circular shifts) instead of\nnormal shifts to increase diffusion of the state, among other things.\n\n<http://eprint.iacr.org/2001/049.pdf>, a paper by Marina Pudovkina discussing plaintext attacks\non the ISAAC keystream generator. Among other things, it notes that the time complexity is Tmet\n= 4.67*10^1240, so it remains a secure cipher for practical applications.\n",
                "subsections": []
            },
            "CAVEATS": {
                "content": "*   There is no method that allows re-seeding of algorithms. This is not really necessary\nbecause one can simply call \"new\" again with the new seed data periodically.\n\nBut he also provides a simple workaround:\n\nAs ISAAC is intended to be a secure cipher, if you want to reseed it,\none way is to use some other cipher to seed some initial version of ISAAC,\nthen use ISAAC's output as a seed for other instances of ISAAC whenever\nthey need to be reseeded.\n\n*   There is no way to clone a PRNG instance. I'm not sure why this is might even be necessary\nor useful. File a bug report with an explanation why and I'll consider adding it to the next\nrelease.\n",
                "subsections": []
            },
            "BUGS": {
                "content": "Please report any bugs or feature requests on the bugtracker website\nhttp://rt.cpan.org/NoAuth/Bugs.html?Dist=Math-Random-ISAAC\n\nWhen submitting a bug or request, please include a test-file or a patch to an existing test-file\nthat illustrates the bug or desired feature.\n",
                "subsections": []
            },
            "AUTHOR": {
                "content": "Jonathan Yu <jawnsy@cpan.org>\n",
                "subsections": []
            },
            "COPYRIGHT AND LICENSE": {
                "content": "Legally speaking, this package and its contents are:\n\nCopyright (c) 2011 by Jonathan Yu <jawnsy@cpan.org>.\n\nBut this is really just a legal technicality that allows the author to offer this package under\nthe public domain and also a variety of licensing options. For all intents and purposes, this is\npublic domain software, which means you can do whatever you want with it.\n\nThe software is provided \"AS IS\", without warranty of any kind, express or implied, including\nbut not limited to the warranties of merchantability, fitness for a particular purpose and\nnoninfringement. In no event shall the authors or copyright holders be liable for any claim,\ndamages or other liability, whether in an action of contract, tort or otherwise, arising from,\nout of or in connection with the software or the use or other dealings in the software.\n",
                "subsections": []
            }
        }
    }
}