1. Fw: code-block

I meant to send this via the list in case others are interested in the code,
but accidentally sent it to Wolf privately (that's a switch).

-- Mike Nelson

> wolfgang fritz wrote:
>
> > ... Sunday mornings  ;-(
> > I need a function that will return, say, any random number from 1 to 10,
> > *except* the number I call it with.
> >
> > function anything_but( integer x )
> > -- return rand() ??
> >
>
>
> Wolf, this will do it:
>
> function anything_but(integer x)
>     integer y
>     y=x
>     while x=y do
>         y=rand(10)
>     end  while
>     return y
> end function
>
> A more generic solution for any range, with as many exclusions as desired:
>
> function anything_but(integer min,integer max,sequence exclude)
>     integer r
>     while 1 do
>         r=rand(max-min+1)+min-1
>         if not find(r,exclude) then return r
>     end while
> end function
>
> -- Mike Nelson
>

new topic     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu