当前位置:网站首页>Generation of random numbers in C language [detailed explanation]
Generation of random numbers in C language [detailed explanation]
2022-06-09 02:47:00 【embelfe_ segge】
Catalog
One 、rand function and srand function
stay C The random function commonly used in language is rand function , It can be generated randomly 0 ~ rand_max The random number , The maximum value varies with the type of definition ,rand The function is contained in the header file stdlib.h in .
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a=rand();
printf("%d",a);
return 0;
}
Running results …………………………………………
You will find that the random number generated each time is the same , because rand The random number generated by a function is a pseudo-random number , It is calculated according to a number and a formula , This number we call “ seeds ”, But this seed is a fixed value after the system is started .
If you want to generate different random numbers every time , that , We're going to use srand function .
srand() The function prototype is :
void srand (usigned int seed);
rand() When generating random numbers , If you use
边栏推荐
- Leetcode 454. Quad add II hash
- Basic method of missing data filling (1) -- k-nearest neighbors (KNN) filling
- Ccf-csp 202012-5 Star Trek 80 points
- Leetcode 1155. N façons de rouler les dés
- Docker installation redis
- Ccf-csp 201909-4 recommended system 100 points
- vins estimator ProcessImage
- export相關知識
- 【无标题】
- Cw2015 alarm function
猜你喜欢

Leetcode 974. And K divisible subarray prefix sum

Leetcode 1352. Product of the last K numbers

Leetcode 1248. Count "graceful subarray" prefix and

Reflection principle and application in C #

Ccf-csp 201903-1 small, medium and large

Handwriting perceptron, KNN, decision tree (ID3) for binary classification of iris

Karmada v1.2 release: open a new era of full-text search

现在VB6.0已经和SQL连接了,但是使用查询功能时无法做到任意条件查询,网上的情况和我的也不太相符,请问该如何实现呢?

Ccf-csp 202104-1 gray histogram 100 points

Jsnpp框架的全链式语法初探
随机推荐
LeetCode 1155. 掷骰子的N种方法**
创建对象之 new 和 newInstance() 的区别
Unity中,继承MonoBehaviour游戏对象的生命周期
LeetCode 1155. 擲骰子的N種方法**
pkg-config --modversion opencvPackage opencv was not found in the pkg-config search path.Perhaps y
vins feature_ track
Cw2015 alarm function
Embedded related open source projects, libraries and materials
Exclusive application for consumer finance license by Weixin Jinke failed
Go技術日報(2022-06-07)——go程序員開發效率神器匯總
Modbus RTU communication routine between Delta Eh3 series PLC and thermostat
Flutter donewidget example
How does JVM handle exceptions? The principle that finally blocks must execute?
Backup and restore methods of MySQL database
Leetcode 1074. Element sum is the number of submatrixes of the target value two-dimensional prefix sum
Ccf-csp 201803-5 quadratic summation 30 points
STM32 flash erase crash
Coulometer scheme
What is the hardware calculation principle of Jerry's ad value? [chapter]
postgresql判断数据库的主从关系