Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

116 Neutral

About walkingcarcass

  • Rank
  1. walkingcarcass

    Not a sequence PRNG, but a distribution of bits?

    Since information on this topic seems to be a bit thin, I've written a faster PRNG. I'm hoping it's OK to use it since the interpretation of the random bits changes quite a lot throughout iterations of the program, so as long as repeated sequences turn up in different places it's OK. Is there anything obviously weak about the code below? It passes statistical tests over a few tens of thousands of iterations, it's about 3 times faster than the SVID 48-bit library functions, and it's based on the Park-Miller "minimal standard" 31-bit PRNG. // This is used as a component of another PRNG. unsigned long int seed; class RandomInitialiser { public: RandomInitialiser () { seed = microsecond_dependent_initial_value(); } }; static RandomInitialiser random_initialiser; unsigned long int prime = 104729; unsigned long int count = 0; unsigned long int random_31_bits () { unsigned long int low = 16807 * (seed&0xFFFF); unsigned long int high = 16807 * (seed >> 16); low += (high&0x7FFF)<<16; low += high>>15; if (low>0x7FFFFFFF) low -= 0x7FFFFFFF; // Hack to increase the sequence length. // XOR-ing random bits with non-random bits still gives // random bits, and the the sequence length is increased by a // factor of GCD(prime, park-miller-sequence-length). low ^= count; if (count > debug_prime) debug_count = 0; return (seed = low); } Do you think I can trust this?
  2. walkingcarcass

    Am I the only Conservitive Programmer/Gamer?

    It really annoys me that the names of our allegiances are misleading. * Why are so many "conservatives" religious? Agnostics are the most conservative in this respect. * Why is it that the "liberals" are usually the ones standing up for old-fashioned values such as freedom of the press? * Why are so many "conservatives" lassaiz-faire economists? Reganism/Thatcherism is downright frivolous. * Why are socialists so often accused of being "communist"? * Why are so many "conservatives" in favour of widespread gun ownership, whereas it is the "liberals" who think there's a difference between a militia and a bunch of people with weapons and that we should restrict the latter? One of the biggest problems with our political system is that the dominant party is dominant in all areas, we can't pick what policies go into the basket, we can only pick one of two or three baskets. This highlights the issue nicely. At the risk of going OT... As a Brit, what I'd like to see is a rule that no political party can put a candidate up for election in more than one constituency. Parties could group together and claim allegiance, but none would have authority over the other. Parliament would hire and fire cabinet members as it sees fit. I'm not sure how this would translate into America. Advantages: * The end of The Whip * We can have, e.g., a liberal Home Office, a conservative Health Minister, etc, etc. Why does one party have to enforce consistency between the Department for Education and the Ministry of Agriculture and fisheries? * Corruption is kept to a fairly local level. * There isn't a massive party vs. party electoral war machine. (I'd also like to stagger the elections so that they happen for a small subset of all ministers but every few weeks.)
  3. Hi. Let's say I want to generate a random 32-bit number such that the expected number of set bits in it is N. I could do this: unsigned int x=0; for (unsigned int i=0; i<32; i++) { x <<= 1; x |= (randominteger() > 32*MAX_VALUE_OF_RANDOM/N); } But this takes something like 800 cpu cycles on a not-very-good PRNG that takes about 25 cycles per iteration. I'm doing this billions of times, perhaps trillions. Normal PRNGs generate sequences, but is there a method which generates x more efficiently?
  4. walkingcarcass

    Animation from PNG

    I have sequentially-numbered .PNG files and I want to compose them into a video of some kind. All the frames are the same size and the framerate is constant. I don't necessarily want an animated .PNG file, it's OK to convert them to something lossy. Linux or Windows tools are fine (Linux preferred). If any of you are really clever, these .PNGs come from saved QImage objects (Qt 3.3). If you know how to save them as a movie clip of some kind directly, that'd be even better. Thanks.
  5. walkingcarcass

    Security -- more than coincidence?

    OK, I'm not usually paranoid but perhaps someone is out to get me... First I started having the occasional login failure with Hotmail, regardless of how careful I was at entering the data. Multiple OSes and browsers. Repeating the attempt would work after a while. Then my password suddenly ceased to work on my University's Kerberos system. Then attempts to change the password repeatedly failed. Hotmail now doesn't let me in at all because of too many failed attempts. Suddenly google doesn't like my password either. I can't use Gmail at all and my customised google home page only logs in on one browser on one machine where the cookie remembers who I am. The home page section for Gmail doesn't load. Normally if I am logged into GMail I can look at my home page without re-entering the password and vice-versa. Not any more. I can't reset my Google password because it gets sent to Hotmail. I can't reset my Hotmail password because it doesn't like the answer to my secret question. I could hardly be more sure that it's correct. I feel cornered. This looks like some sort of patterned attack. What do you think, should I be worried? I am worried.
  6. walkingcarcass

    wget usage

    Hi. I'm trying to download the following from a website: http://site.com/features/X/a.html http://site.com/features/X/b.html http://site.com/features/X/c.html http://site.com/features/Y/d.html http://site.com/features/Z/e.html etc. I also want to download embedded images and all links for these pages, but not following links outside site.com/features/* Man pages for wget led me to try this: Quote:wget -r -l2 http://site.com/features But this simply gets site.com/features/index.html and site.com/robots.txt. Their robots.txt disallows several areas of the site but not features/ The other thing is I have a text file listing http://site.com/features/X/ http://site.com/features/Y/ http://site.com/features/Z/ etc But using -i list.txt still just gets files called index.html. The other thing is I have an html file which links to one file in each of /features/*/ but if I use recursive downloading like this: Quote:wget -x -r -l2 --convert-links -p -Dsite.com pagewithlinks.html Then it tries to download masses of stuff from elsewhere in the site, and doing -Dsite.com/features causes only only pagewithlinks.html to be downloaded. I'm betting the last approach is the most promising. Anyone know how to restrict recursive downloading to links within site.com/somedirectory/* ?
  7. walkingcarcass

    cout blah is backwards... sometimes

    Quote:Original post by Anonymous Poster Think of the cout statement like this std::cout << (" A " << (test() << (" B " << (test() << (" C " << (test() << ("\n"))))))); That can't be right. In the expression cout << A << B; How do we evaluate (A << B)? What happens is: cout is an instance of std::ostream, (cout << A) returns cout! Ever overloaded it? Seen code like this? std::ostream & operator (std::ostream & o, const MyClass & c) { o << blah; return o; } So it *has* to be ((cout << A) << B);
  8. walkingcarcass

    cout blah is backwards... sometimes

    But IIRC the operator<< as well as operator+ and operator&& etc all have the same order of evaluation, e.g. replacing the main function above, the statement if(test()||test()||test()) would early-out on the second test() and never execute the third. And it's not an argument that the arithmetic operators are different: a-c+b is (a-c)+b not a-(c+b). Why is << so weird?
  9. #include <iostream> int x = 0; int test () { int r = x; x += 3; return r; } int main () { std::cout << " A " << test() << " B " << test() << " C " << test() << "\n"; return 0; } The output of this is Quote:A 6 B 3 C 0 So cout is printing its arguments left-to-right but computing the functions' return values right-to-left. WTF? Compiled with "g++ test.cpp", gcc version 4.1.2 20060928 (prerelease) (Ubuntu 4.1.1-13ubuntu5)
  10. walkingcarcass

    g++ broken?

    test.hpp: class Test { public: double test ( unsigned int i, double * buffer, void * argument = NULL) const; }; test.cpp: #include "test.hpp" output: Quote:g++ -c test.cpp test.hpp:5: error: ‘NULL’ was not declared in this scope This suddenly started. Code that compiled yesterday now fails with this error. What's going on?
  11. walkingcarcass

    konqueror forgets view mode

    Aargh! It remembers the icon size but not the view mode. Things like this make me feel like the grumpy old bastard in Amélie when she sabotages all the little things in his house. Thanks anyway.
  12. walkingcarcass

    quickie -- probability distribution.

    Homework? What I'm trying to do is have several threads run every N seconds, but with a slight random variation in N to prevent load spikes. On second thoughts I can probably get away with uniform gaps of [N-x...n+x] seconds, but I'm still curious as to what the first-thought distribution would be. It itches me because it's very similar to the Gaussian, yet clearly not the same.
  13. walkingcarcass

    Suspicious glibc RNG?

    You're right -- I forgot to initialise counts[] Quote: 3685 buckets hit 0times. 3677 buckets hit 1times. 1822 buckets hit 2times. 630 buckets hit 3times. 147 buckets hit 4times. 33 buckets hit 5times. Makes much more sense now! Here's the profile for rand_r on 1,000,000 samples:Quote: 366384 buckets hit 0times. 369196 buckets hit 1times. 185028 buckets hit 2times. 60958 buckets hit 3times. 14929 buckets hit 4times. 2952 buckets hit 5times. 481 buckets hit 6times. 64 buckets hit 7times. And here's the same for SVID:Quote: 367636 buckets hit 0times. 368606 buckets hit 1times. 183261 buckets hit 2times. 61478 buckets hit 3times. 15362 buckets hit 4times. 3045 buckets hit 5times. 531 buckets hit 6times. 71 buckets hit 7times. 8 buckets hit 8times. Does anyone know if this is sensible? Looks about right. I think, generally, SVID has slightly higher values for 6 or 7 bucket collisions. Wouldn't that mean it was more predictable than rand_r? Maybe it hits a subset of outputs with higher probability but that subset itself wanders in the long term. If this conjecture is right, it might mean rand_r is cryptographcally stronger than SVID for relatively short messages. Going off topic, but it's an interesting thought.
  14. walkingcarcass

    Suspicious glibc RNG?

    The idea is that an entries in the counts[] array should be 1 on average because there are NUM samples and counts has NUM elements. If N was 10 counts would be something like {1,0,1,3,0,3,0,1,1,0} and, intuitively, as N grows, the numbers in counts[] will still be quite small. counts_counts for this example would be {4,4,0,2}: 4 zeros, 4 ones, no twos and 2 threes, and you'd expect the entry in counts_counts to be smaller as i is larger. What this example shows is that counts_counts contains nonzero values for many large i which implies that some buckets in counts[] are being hit very often.
  15. walkingcarcass

    Suspicious glibc RNG?

    Follow-up, I just replaced the SVID RNG with POSIX 1.1 rand_r and the collision results are pretty much exactly the same. What gives?
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!