Created
June 6, 2019 08:30
-
-
Save cmonkey/94a30efe3d1eff7c52a3999e43f5d91c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket | |
(require json) | |
(define filename "combined.json") | |
(define timezone-data (call-with-input-file filename read-json)) | |
(define (random-sample object [max-size 5]) | |
(cond | |
((hash? object) | |
(for/hash ([(k v) (in-hash object)]) | |
(values k (random-sample v max-size)))) | |
((list? object) | |
(let ([len (length object)]) | |
(if (> len max-size) | |
(let ([samples (sort (build-list max-size (lambda (x) (random len))) <)]) | |
(for/list ([(x position) (in-indexed (in-list object))] | |
#:when (member position samples)) | |
(random-sample x max-size))) | |
(for/list ([x (in-list object)]) | |
(random-sample x max-size))))) | |
(#t object))) | |
(random-sample timezone-data 2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment