在线时间1148 小时
UID2108106
ST金币0
蝴蝶豆24
注册时间2015-2-4
论坛元老
- 最后登录
- 2020-9-4
|
a0a.1 32b0c
随便玩玩
数据全放ram,add watch 不输出!.
均值什么的随便算算..
- union floathex
- {
- unsigned int hexvalue;
- float floatvalue;
- };
- floathex rand[20000];
- double sum;
- double average;
- double var;
- double _var;
复制代码 初始化:
- void HAL_RNG_MspInit(RNG_HandleTypeDef *hrng)
- {
- __HAL_RCC_RNG_CLK_ENABLE();
- }
- __________________________________________
- // IN MAIN()
- HAL_Init();
- SystemClock_Config();
-
- hrng.Instance = RNG;
- __HAL_RCC_RNG_CONFIG(RCC_RNGCLKSOURCE_MSI) ;
- HAL_RNG_Init(&hrng);
- //SET_BIT(RNG->CR, RNG_CR_RNGEN);
- state=HAL_RNG_GenerateRandomNumber(&hrng,&rand[0].hexvalue);
- state=HAL_RNG_GenerateRandomNumber(&hrng,&rand[0].hexvalue);
- state=HAL_RNG_GenerateRandomNumber(&hrng,&rand[0].hexvalue);
- state=HAL_RNG_GenerateRandomNumber(&hrng,&rand[0].hexvalue);
复制代码 看上去似乎是可以的..
然后生成随机数(0,1)来简单看看.
虽然我学识浅薄,但品均值大概在0.5左右还是知道的...
- while(1)
- {
- int i;
- for(i=0;i<20000;i++)
- {
- state=HAL_RNG_GenerateRandomNumber(&hrng,&rand[i].hexvalue);
- rand[i].hexvalue = (rand[i].hexvalue>>9) | 0x3f800000;
- rand[i].floatvalue -= 1.0f;
- }
复制代码 结果略关虚拟机后才想起没截图...)
Anyway ,
明天又周末了
|
|