# Random seed generator algorithm, who can explain this algo to me? is this a good one? what's the design about it?

``````function generateSeed(uint256 tokenId) public view returns (uint256) {
uint256 r = random(tokenId);
uint256 headSeed = 100 * (r % 7 + 10) + ((r >> 48) % 20 + 10);
uint256 faceSeed = 100 * ((r >> 96) % 6 + 10) + ((r >> 96) % 20 + 10);
uint256 bodySeed = 100 * ((r >> 144) % 7 + 10) + ((r >> 144) % 20 + 10);
uint256 legsSeed = 100 * ((r >> 192) % 2 + 10) + ((r >> 192) % 20 + 10);
``````

}

the code is from owls nft: https://etherscan.io/address/0xe2e27b49e405f6c25796167b2500c195f972ebac#code

In your code, the calculation of `headSeed` is deterministic from the value of `r`. The source of randomness comes from the function `random()`.

``````    function random(uint256 tokenId) private view returns (uint256 pseudoRandomness) {
pseudoRandomness = uint256(
keccak256(abi.encodePacked(blockhash(block.number - 1), tokenId))
);

return pseudoRandomness;
}
``````

Randomness here is gotten from blockhash of the last block. It is recommended not to use block values as a source of randomness as it can be controlled by other actors https://swcregistry.io/docs/SWC-120 . One of the recommended ways is to use Chainlink VRF Verifiable Random Function

Nonetheless, if the NFT value is not really high (and the benefit of manipulating the randomness is not high compared to the resource to obtain the block mining (proposing) right), the usage of blockhash is justifiable because of its simplicity.