Thread: Came back to random numbers and got decent randomness

  1. #16
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Quote Originally Posted by hamster_nz View Post
    That code is completely unencumbered, so anybody can use it however you like. Pfease feel free to use it in a MIT Licensed project.

    Oh, I don't know about PNG files, but BMP files are pretty braindead simple. See GitHub - hamsternz/my_bmp: A utility for writing out RGB pixel data as BMP files. for some code you can lift.

    Oh I did look at the cause of the bias in the least significant bits of your my_rand() - it was the multiplication just before the end. It's because
    odd * odd = odd
    odd * even = even
    even * odd = even
    even * even = even
    So if the two numbers being multiplied are 'pretty much random' then the result of the multiply will have three '1's for every '0' in the LSB.
    Nah, I think the bias towards odd is down to the add at the end, the add was to stop the last bits constantly being 0, I would've needed to use something a bit more flexible there but since the other code is fine under MIT License I'll just go with that and put and end to this rng stuff, the inspiration for this code came from the Xn+1 thing I saw in a video recently, was trying to implement that in code and make use of the almost endless branching, seems like I failed there however, I'll take a look at that BMP code you pointed me too though. Honestly I think these image format libraries over complicate things though, all they need to do is read/write the format, whether the raw image data follows the expected format is none of their concern, that's for a wrapper library to take care of when it takes in an RGBA array or RGBA function.

  2. #17
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Was trying to setup an automated download of the library (for which I can base other project automated downloads off of) but keep getting unexpected end of file error, no matter how many times I check the result is the same as the example I found online, anyone understand what I'm doing wrong here:
    RNG_LIBS=-l testU01 -l my_bmp
    is_dir=if [ -d "$1" ] && $2
    no_dir=if [ ! -d "$1" ] && $2
    mkdir=$(call no_dir,$1,mkdir "$1")
    clone=$(call no_dir,cloned/$1,git --git-dir cloned clone $1 $2)
    pull=git --git-dir cloned/$1 pull
    	$(call mkdir,cloned)
    	$(call clone,$(BMP_DIR),$(BMP_PRJ))
    	$(call pull,$(BMP_DIR),$(BMP_PRJ))

  3. #18
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    *face palms* If there's an easy way to do it and a hard way, I naturally go with hard before noticing the easy:
    is_dir=$(if $(wildcard $1 $1/*),$2,$3)
    mkdir=$(call is_dir,$1,echo,mkdir "$1")
    github_pull=cd $(CLONE_DIR)$(call is_dir,$(CLONE_DIR)/$1,/$1 && git pull, && git clone$2.git)
    	$(call mkdir,cloned)
    	$(call github_pull,$(BMP_DIR),$(BMP_PRJ))

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Scale back size of Numbers while maintaining proportion
    By kerrymaid in forum C Programming
    Replies: 5
    Last Post: 10-23-2011, 01:31 PM
  2. Replies: 4
    Last Post: 11-16-2004, 07:29 AM
  3. Replies: 3
    Last Post: 07-24-2002, 08:46 AM
  4. random number - replaying back.. pls help!
    By Unregistered in forum C++ Programming
    Replies: 7
    Last Post: 01-18-2002, 02:34 AM

Tags for this Thread