• R/O
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

BASIC compiler/interpreter for PIC32MX/MZ-80K (suspended)


Commit MetaInfo

Revision142 (tree)
Time2016-07-25 08:17:44
Authorkmorimatsu

Log Message

Use Xorshift for rnd() function.

Change Summary

Incremental Difference

--- mips/branches/nauplia/library.c (revision 141)
+++ mips/branches/nauplia/library.c (revision 142)
@@ -133,21 +133,13 @@
133133 }
134134
135135 int lib_rnd(){
136- int i,j,rnd;
137- rnd=g_rnd_seed;
138- for (i=0;i<15;i++) {
139- j=rnd;
140- j^=(j>>1);
141- j^=(j>>2);
142- j^=(j>>9);
143- j>>=3;
144- j&=0x01;
145- j|=rnd<<1;
146- j&=0x0000FFFF;
147- rnd=j;
148- }
149- g_rnd_seed=rnd;
150- return rnd&0x00007FFF;
136+ int y;
137+ y=g_rnd_seed;
138+ y = y ^ (y << 13);
139+ y = y ^ (y >> 17);
140+ y = y ^ (y << 5);
141+ g_rnd_seed=y;
142+ return y&0x7fff;
151143 }
152144
153145 char* lib_chr(int num){
--- mips/branches/nauplia/run.c (revision 141)
+++ mips/branches/nauplia/run.c (revision 142)
@@ -114,7 +114,7 @@
114114
115115 // Initialize the other parameters
116116 // Random seed
117- g_rnd_seed=0x3045;
117+ g_rnd_seed=2463534242;
118118 // Clear variables
119119 for(i=0;i<ALLOC_BLOCK_NUM;i++){
120120 g_var_mem[i]=0;
--- mips/branches/zoea/run.c (revision 141)
+++ mips/branches/zoea/run.c (revision 142)
@@ -112,7 +112,7 @@
112112
113113 // Initialize the other parameters
114114 // Random seed
115- g_rnd_seed=0x3045;
115+ g_rnd_seed=2463534242;
116116 // Clear variables
117117 for(i=0;i<ALLOC_BLOCK_NUM;i++){
118118 g_var_mem[i]=0;
--- mips/branches/zoea/library.c (revision 141)
+++ mips/branches/zoea/library.c (revision 142)
@@ -176,21 +176,13 @@
176176 }
177177
178178 int lib_rnd(){
179- int i,j,rnd;
180- rnd=g_rnd_seed;
181- for (i=0;i<15;i++) {
182- j=rnd;
183- j^=(j>>1);
184- j^=(j>>2);
185- j^=(j>>9);
186- j>>=3;
187- j&=0x01;
188- j|=rnd<<1;
189- j&=0x0000FFFF;
190- rnd=j;
191- }
192- g_rnd_seed=rnd;
193- return rnd&0x00007FFF;
179+ int y;
180+ y=g_rnd_seed;
181+ y = y ^ (y << 13);
182+ y = y ^ (y >> 17);
183+ y = y ^ (y << 5);
184+ g_rnd_seed=y;
185+ return y&0x7fff;
194186 }
195187
196188 char* lib_chr(int num){