So, here I finally made a new routine that seems *really* random. When I didrectly used it in my map generating routine to take the result of this routine seeded with 0 and mod 6, the tile output showed no patterns whatsoever. However, I attained it by keeping the RTCtimer at bay for a *long*, *random*, time. Anyways, the routine on it's own, which can even seed itself or get seeded by the RTC_GetTicks:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| unsigned short random(int extra_seed) { int seed = 0; int seed2 = 0; for(int i = 0; i < 32; i++ ){ seed <<= 1; seed |= (RTC_GetTicks()%2); } for(int i = 0; i < 32; i++ ){ seed2 <<= 1; seed2 |= (RTC_GetTicks()%16); } seed ^= seed2; seed = (( 0x41C64E6D*seed ) + 0x3039); seed2 = (( 0x1045924A*seed2 ) + 0x5023); extra_seed = (extra_seed)?(( 0xF201B35C*extra_seed ) + 0xD018):(extra_seed); seed ^= seed2; if(extra_seed){ seed ^= extra_seed; } return ((seed >> 16) ^ seed) >> 16; }
|
It basically gets one bit from the timer at a time for the first seed, and then the second, "darker" seed (higher chance of filled bits), each bit gets 4 oppertunities to be seeded with a 1. It then goes through the standard wacky operations to fill in the bitfield better, xors the available seeds together, and returns them as a short. Very loosly based on simon's routine.
It's random *depending on how it's used*. If you use it every now and then, it will be *surely* random, if you seed it with RTC_GetTicks or another varying number (even with a seed of 0 it will still be random, though). In loops, it's fixed by slowing down operation in tradeoff for randomiscity:
1 2 3 4
| for(int i = 0; i < 3600; i++) { (*(map+i)).natural_cell = random(random(RTC_GetTicks()))%6; OS_InnerWait_ms(random(0)%64); } |
As you see above, the actual random value is seeded by another random value that is not seeded, which worked really well. For the OS_InnerWait_ms, I have it wait for an unseeded random time, mod 64 (so it won't wait a very long time, and since the RTC timer increments 64 times a second, it should give it long enough to increment in usual cases.
All because of a rand() and srand() linking error

fun night spent.