{
    "Function": "_random",
    "File": "contracts/lib/solady/test/utils/TestPlus.sol",
    "Parent Contracts": [],
    "High-Level Calls": [],
    "Internal Calls": [
        "calldatacopy(uint256,uint256,uint256)",
        "byte(uint256,uint256)",
        "sload(uint256)",
        "calldatasize()",
        "keccak256(uint256,uint256)",
        "byte(uint256,uint256)",
        "byte(uint256,uint256)",
        "mstore(uint256,uint256)",
        "sstore(uint256,uint256)",
        "keccak256(uint256,uint256)",
        "mload(uint256)",
        "calldatasize()"
    ],
    "Library Calls": [],
    "Low-Level Calls": [],
    "Code": "function _random() internal returns (uint256 r) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            // This is the keccak256 of a very long string I randomly mashed on my keyboard.\n            let sSlot := 0xd715531fe383f818c5f158c342925dcf01b954d24678ada4d07c36af0f20e1ee\n            let sValue := sload(sSlot)\n\n            mstore(0x20, sValue)\n            r := keccak256(0x20, 0x40)\n\n            // If the storage is uninitialized, initialize it to the keccak256 of the calldata.\n            if iszero(sValue) {\n                sValue := sSlot\n                let m := mload(0x40)\n                calldatacopy(m, 0, calldatasize())\n                r := keccak256(m, calldatasize())\n            }\n            sstore(sSlot, add(r, 1))\n\n            // Do some biased sampling for more robust tests.\n            // prettier-ignore\n            for {} 1 {} {\n                let d := byte(0, r)\n                // With a 1/256 chance, randomly set `r` to any of 0,1,2.\n                if iszero(d) {\n                    r := and(r, 3)\n                    break\n                }\n                // With a 1/2 chance, set `r` to near a random power of 2.\n                if iszero(and(2, d)) {\n                    // Set `t` either `not(0)` or `xor(sValue, r)`.\n                    let t := xor(not(0), mul(iszero(and(4, d)), not(xor(sValue, r))))\n                    // Set `r` to `t` shifted left or right by a random multiple of 8.\n                    switch and(8, d)\n                    case 0 {\n                        if iszero(and(16, d)) { t := 1 }\n                        r := add(shl(shl(3, and(byte(3, r), 0x1f)), t), sub(and(r, 7), 3))\n                    }\n                    default {\n                        if iszero(and(16, d)) { t := shl(255, 1) }\n                        r := add(shr(shl(3, and(byte(3, r), 0x1f)), t), sub(and(r, 7), 3))\n                    }\n                    // With a 1/2 chance, negate `r`.\n                    if iszero(and(0x20, d)) { r := not(r) }\n                    break\n                }\n                // Otherwise, just set `r` to `xor(sValue, r)`.\n                r := xor(sValue, r)\n                break\n            }\n        }\n    }"
}