Cでpythonのrandom.randintに似たものを実装しようとしています.
私は次のようなことをします:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
srand(time(NULL));
int randInt(int lBound, int uBound){
return (rand()%(uBound-lBound+1))+lbound;
}
ただし、RAND_MAX が uBound の倍数でない場合、分布はわずかに歪んでいます。
より良い迅速で汚い方法はありますか?