The random key plays a basic role in the design of any cryptographic algorithms. In this paper, a proposed model for generating a random key is presented, which will be used for security purposes. Chicken swarm optimization (CSO) and HTML parser are used for scattering the bits of the key. The statistical tests of randomness have given good and acceptable security results. The proposed key generation method was programmed by JavaScript language.