A simple pseudo-random number occurrence algorithm (RPM)

Source: Internet
Author: User

Source: A simple pseudo-random number occurrence algorithm

//This code is purely for communication purposes, e.g. as a security area, at your own risk.#include<stdint.h>#include<stdlib.h>//! \brief Random seedStaticuint16_t S_hwrandomseed =0xaa55;Staticuint8_t s_chrandomtable[] = {                0x12,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF,                0xF1,0xe2,0xd3,0xc4,0xb5,0xa6,0x97,0x88};/*! \note set Random Generator seed * \param hwseed random seed* \return None*/voidset_random_seed (uint16_t hwseed) {s_hwrandomseed^=hwseed;}/*! \note get a random integer* \param none* \return random integer value*/uint16_t get_random_u16 (void) {uint16_t*phwresult = (uint16_t *) &s_chrandomtable[(S_hwrandomseed &0x0E)]; *phwresult + =S_hwrandomseed; S_hwrandomseed^= *Phwresult; return*Phwresult;}/*! \note get a random byte* \param none* \return random integer value*/uint8_t get_random_u8 (void ){    returnget_random_u16 ();}

/* The most commonly used random algorithm, C language standard library function results and this is consistent here is 32-bit machine, 8-bit machine add ul, change int to long */ int seed; void srand (int  s) {    = s;} int rand () {    226954771;}

A simple pseudo-random number occurrence algorithm (RPM)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.