LoginSignup
1
0

wslで、最小のカーネルをコンパイル その11

Posted at

概要

wslで、kernel.elfのコンパイル、やってみた。
乱数を考察。

乱数比較

実験  3の剰余  周期
1 マイナス有り 長い
2 マイナス有り 長い
3 ok 短い

実験1

#include <stdio.h>

char randseed = 123;
char rand(void) {
	return (randseed = randseed * 5 - 1);
}
int main(void) {
    printf("%d \n", rand() % 3);
    printf("%d \n", rand() % 3);
    printf("%d \n", rand() % 3);
    printf("%d \n", rand() % 3);
    printf("%d \n", rand() % 3);
    printf("%d \n", rand() % 3);
    printf("%d \n", rand() % 3);
    int i = 0;
	while (i < 4)
	{
		if (rand() < 0)
		{
			printf("zun ");
			i++;
		}
		else
		{
			printf("doko ");
			i = 0;
		}
	}
	printf("doko kiyosi!!");

    return 0;
}
0 
0 
-1 
0 
1 
2 
0 
zun doko zun doko doko zun doko doko zun zun zun doko zun zun zun doko zun zun zun zun doko kiyosi!!

実験2


#include <stdio.h>

int a = 12;
int rand() {
	int x = a;
	x ^= x << 13;
	x ^= x >> 17;
	x ^= x << 5;
	return a = x;
}
int main(void) {
    printf("%d \n", rand() % 3);
    printf("%d \n", rand() % 3);
    printf("%d \n", rand() % 3);
    printf("%d \n", rand() % 3);
    printf("%d \n", rand() % 3);
    printf("%d \n", rand() % 3);
    printf("%d \n", rand() % 3);
    int i = 0;
	while (i < 4)
	{
		if (rand() < 0)
		{
			printf("zun ");
			i++;
		}
		else
		{
			printf("doko ");
			i = 0;
		}
	}
	printf("doko kiyosi!!");
    return 0;
}

0 
1 
0 
2 
0 
0 
-1 
zun doko zun doko zun doko doko doko doko doko zun doko zun doko doko zun zun doko zun zun zun zun doko kiyosi!!

実験3

#include <stdio.h>

static int randseed = 12345;
int rand(void) {
	return (randseed = randseed * 12345 + 17);
}
int main(void) {
    printf("%d \n", rand() % 3);
    printf("%d \n", rand() % 3);
    printf("%d \n", rand() % 3);
    printf("%d \n", rand() % 3);
    printf("%d \n", rand() % 3);
    printf("%d \n", rand() % 3);
    printf("%d \n", rand() % 3);
    int i = 0;
	while (i < 4)
	{
		if (rand() % 2 < 1)
		{
			printf("zun ");
			i++;
		}
		else
		{
			printf("doko ");
			i = 0;
		}
	}
	printf("doko kiyosi!!");

    return 0;
}
2 
2 
1 
2 
0 
0 
2 
doko zun doko zun doko zun zun zun zun doko kiyosi!!

以上。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0