Or:

(build-list n (lambda (dont-care) (make-random-string)))

On Tue, Oct 25, 2016 at 10:42 PM, Robby Findler <ro...@eecs.northwestern.edu
> wrote:

> I would probably write that function like this:
>
> #lang racket
>
> (provide
>  (contract-out
>   [make-a-string (-> non-empty-string? string?)]))
>
> (define (make-a-string candidates)
>   (apply
>    string
>    (for/list ([i (in-range (random 100))])
>      (string-ref candidates (random (string-length candidates))))))
>
> (module+ test
>   (require rackunit)
>   (check-true (string? (make-a-string "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123
> 456789"))))
>
>
> hth,
> Robby
>
>
> On Tue, Oct 25, 2016 at 9:39 PM,  <meino.cra...@gmx.de> wrote:
> > Hi,
> >
> > I want to create a list of random strings.
> > For that I have created a function, which returns a string
> > of random length and random contents.
> >
> > Then I used
> >     make-list n (make-random-string)
> >
> > to create that list....and get back a list filled with n
> > identical strings.
> >
> > hmmmm...
> >
> > make-list calls make-random-string ones and the rest
> > is repetition.
> >
> > If I think to have understood correctly for-loops and such are
> > somehow of "imperative, non-functional old-school programming style"
> > and map/apply and friends are the tools of the real racket programmer
> > ;) this lead to a more general "problem" ("problem" only for a newbie
> > like me may be)...:
> >
> > Since make-list calls its list-argument only once, the above does not
> > work in the sense it is wanted, so make-list creates only lists of
> > the same thing.
> >
> > Therefore to prevent "for" and friends, I have to call make-list
> > with the empty list as list-argument and then map the
> > make-random-string to each of them, which ensures that
> > make-random-string is not called once.
> > That feels ugly.
> >
> > What is a good "racket-ish" of "racket-y" way (nothing negative
> > meant...just a play with words by someone, who is no native
> > speaker...;) to do something n times without old-school
> > for-and-friends-loops.
> >
> > Here is the code:
> >
> > #lang racket
> > (require racket/random)
> > (require racket/string)
> >
> > (define charseq "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" )
> > (define minchars  7)
> > (define maxchars 15)
> > (define numlists 6)
> >
> > (define (make-random-string seq min max)
> >   ( let ((lenstr (random min max)))
> >         ( apply string (random-sample seq lenstr))))
> >
> > (define (make-list-of-random-strings cnt seq min max )
> >   (make-list cnt (make-random-string seq min max )))
> >
> > (define (make-list-of-lists numsublists)
> >   ( make-list numsublists (make-list-of-random-strings numlists charseq
> minchars maxchars)))
> >
> > ( define (main)
> >          (make-list-of-lists 20))
> >
> > (main)
> >
> > Any improvement is welcome!
> >
> > Cheers,
> > Meino
> >
> >
> >
> > --
> > You received this message because you are subscribed to the Google
> Groups "Racket Users" group.
> > To unsubscribe from this group and stop receiving emails from it, send
> an email to racket-users+unsubscr...@googlegroups.com.
> > For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to