﻿ Prizm Useful Routines -- post here!
20 June, 2013, 05:45:37
 OmnomIRC You must Register, be logged in and have at least 40 posts to use this shout-box! If it still doesn't show up afterward, it might be that OmnomIRC is disabled for your group or under maintenance.Note: You can also use an IRC client like mIRC, X-Chat or Mibbit to connect to an EFnet server and #omnimaga.

 Pages: 1 [2] 3 4 5   Go Down
 Author Topic: Prizm Useful Routines -- post here! -  (Read 4068 times) 0 Members and 1 Guest are viewing this topic.
Guest
 « Reply #15 on: 09 September, 2011, 00:55:22 » 0

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:

 1234567891011121314151617181920 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:

 1234 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.
 Logged
 Pages: 1 [2] 3 4 5   Go Up