Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsreader4.netcologne.de!news.netcologne.de!xlned.com!feeder7.xlned.com!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.051 X-Spam-Evidence: '*H*': 0.90; '*S*': 0.00; '*the': 0.09; 'bytes,': 0.09; 'random': 0.14; 'compression': 0.16; 'exploits': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; ':-)': 0.16; 'wrote:': 0.18; 'thu,': 0.19; 'import': 0.22; '31,': 0.24; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'tim': 0.29; 'message- id:@mail.gmail.com': 0.30; 'chase': 0.31; 'subject:that': 0.31; 'file': 0.32; 'quite': 0.32; 'skip:s 30': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'acceptable': 0.36; 'data,': 0.36; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'truly': 0.60; 'units': 0.60; 'length': 0.61; 'full': 0.61; 'talking': 0.65; 'random,': 0.84; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=14upqji6d8Q2TrbI6eZ3bDVDw0PMzbEQugPzT8Yoa8I=; b=Y1e0emjJpKOpoGA9wrr6v+PPcsrfrehxMu6VZ07TYrlzh3xigtZXOSGZWKUJDvbP0N qmBq+N/1rgJ68uAzk9aCF3b6zTrfYmgRWHTlJz1m49+EoR4vnFxVAiLmRZhvZBksEzs6 KEMvFfVIxYz3Ip6C+o9Exbof2zEnsgZgQAclngRLnM1a0/WNbEjM2uDHSy1ygbzR2+0O Kn4M0kWe3RCAgHubdQZtkduQCeV/xz3NDoKPJhwSon4YD8HRbB4fZzZ7gwqspWLza7dI qK8ABXpSWNgXDF+pniR6vf6ilIrzgP33TGiOGgDlxCp4Ds/CJYg6Mu9WFPxofMrbXwLz iseQ== MIME-Version: 1.0 X-Received: by 10.66.25.208 with SMTP id e16mr847520pag.131.1383176471905; Wed, 30 Oct 2013 16:41:11 -0700 (PDT) In-Reply-To: <20131030180139.7080b190@bigbox.christie.dr> References: <205bfa4f-29de-43de-be5a-72a12d77d0c9@googlegroups.com> <0f857f7f-5947-4b3a-805d-0e9b888dfd48@googlegroups.com> <20131030180139.7080b190@bigbox.christie.dr> Date: Thu, 31 Oct 2013 10:41:11 +1100 Subject: Re: Algorithm that makes maximum compression of completly diffused data. From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 40 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1383176481 news.xs4all.nl 15990 [2001:888:2000:d::a6]:52971 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:58142 On Thu, Oct 31, 2013 at 10:01 AM, Tim Chase wrote: > On 2013-10-30 21:30, Joshua Landau wrote: >> started talking about compressing *random data* > > If it's truly random bytes, as long as you don't need *the same* > random data, you can compress it quite easily. Lossy compression is > acceptable for images, so why not random files? :-) Maybe. But what if it's not truly random, but only pseudo-random? # create a file full of random data import random seed = random.getrandbits(32) length = random.getrandbits(16) # in four-byte units random.seed(seed) inname = "random.txt" namez = inname + '.rnz' with open(inname, "wb") as bigfile: for _ in range(length): bigfile.write(random.getrandbits(32).to_bytes(4,"big")) # compress that file with open(namez, "wb") as smallfile: smallfile.write(seed.to_bytes(4,"big")) smallfile.write(length.to_bytes(4,"big")) # uncompress it with open(namez, "rb") as f: seed = int.from_bytes(f.read(4),"big") length = int.from_bytes(f.read(4),"big") random.seed(seed) with open("out_" + inname, "wb") as bigfile: for _ in range(length): bigfile.write(random.getrandbits(32).to_bytes(4,"big")) Voila! Very impressive compression ratio, and exploits the very randomness of the data! ChrisA