I am building a lottery D-App now based on Ethereum. While creating a smart contract, I found that Solidity has no method to generate random numbers. Solidity is not capable of creating random numbers. So I've created my own method to generate random numbers using timestamp.
Is it possible to make this method as a library so that everyone can use my method with a simple import command?
If it's possible, many developers could save their time.
I believe you could deploy your PRNG contract, and allow other callers to use it, or alternatively publish its code on some public repository (e.g. github), allowing developers to add it directly in their code (using the import command).
Please note using the block timestamp as a source of randomness is considered insecure: https://medium.com/dedaub/bad-randomness-is-even-dicier-than-you-think-7fa2c6e0c2cd
This post suggests overcoming the randomness challenge using an external oracle (requires trust in the oracle operator) or some commit-reveal scheme (e.g. several participants send hashes of random seeds - this is the commitment, and later they all reveal the preimages. The seed is defined to be some mix of the preimages, e.g. their XOR). Another approach is to use a VDF (verifiable delay function). Here is an example of an implementation of a VDF by StarkWare including detailed information on how can it be used to provide secure randomness on Ethereum https://medium.com/starkware/presenting-veedo-e4bbff77c7ae.