Paste: first shot at random.org fun

Author: _hrrld
Mode: factor
Date: Thu, 6 Nov 2008 02:11:16
Plain Text |
! Copyright (C) 2008 Harold Hausman
! See http://factorcode.org/license.txt for BSD license.
USING: http.client kernel sequences splitting accessors make math.parser combinators ;
IN: randomdotorg

! http://www.random.org/integers/?num=10&min=1&max=6&col=1&base=10&format=plain&rnd=new

TUPLE: randomdotorg num min max base ;
C: <randomdotorg> randomdotorg
GENERIC: get ( randomdotorg -- {num} )

: (get-clean) ( nums http-response -- {num} )
  [ 10 = ] trim-right "\n" split swap drop ; 

M: randomdotorg get ( randomdotorg -- {num} )
  { [ base>> ] [ max>> ] [ min>> ] [ num>> ] } cleave  
  [ "http://www.random.org/integers/?num=" , number>string , 
    "&min=" , number>string ,
    "&max=" , number>string ,
    "&col=1&base=" , number>string ,
    "&format=plain&rnd=new" ,
  ] { } make "" swap [ append ] each http-get (get-clean) ;

New Annotation

Summary:
Author:
Mode:
Body: