/부터 srand urandom의 등 ...생성 진정한 난수
이 내 난수 함수
int rand2(int lim)
{
static int a = 34; // could be made the seed value
a = (a * 32719 + 3) % 32749;
return ((a % lim) + 1);
}
구조체 난 것입니다 카드가 이미 터진 경우 알 (0 = NO, 1 예)
typedef struct s_game
{
int *cards;
int state;
unsigned int dat_rand;
} t_game;
int main()
{
t_game game;
int i;
int rd;
i = 0;
game.cards = malloc(sizeof(*game.cards) * 52);
while(i < 52)
{
rd = rand2(52);
if(game.cards[rd] == 0)
{
game.cards[rd] = 1;
printf("i:%d\n rd: %d\n", i, rd);
i++;
}
}
}
하지만 내 출력이 항상 동일, 각각의 카드가 더 나은 랜덤 함수를 구경에게 너무 메신저 검색을 동시에 전달 또는 다른 내 배달을 채우기위한 방법
귀하의 기능이 표준 기능보다 더 이상하다고 생각하게 만드는 요인은 무엇입니까? – JJJ
인터넷 검색 ** [ "임의 번호 c"] (http://stackoverflow.com/questions/822323/how-to-generate-a-random-number-in-c) ** 결과가 없습니다. 나는 그걸 믿지 않는다. ... – ppeterka
물론,하지만 내 자신의 임의의 기능을 원한다. – Saxtheowl