1. code-block

... 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

new topic     » topic index » view message » categorize

2. Re: code-block

function anything_but(integer x)
  integer i i=x
  while i=x do i=rand(yourmaximumhere) end while
  return i
end function

new topic     » goto parent     » topic index » view message » categorize

3. Re: code-block

That'll work, but I'd do it this way:

function rand_not( integer x )
  integer r
  r = rand( max-1 )
  if r >= x then r += 1 end if
  return r
end function

You're guaranteed to only have one call to rand().

Matt

--- "Darth Maul, aka Matt" <uglyfish87 at HOTMAIL.COM> wrote:
> function anything_but(integer x)
>   integer i i=x
>   while i=x do i=rand(yourmaximumhere) end while
>   return i
> end function


__________________________________________________
Do You Yahoo!?
Yahoo! Mail - Free email you can access from anywhere!
http://mail.yahoo.com/

new topic     » goto parent     » topic index » view message » categorize

4. Re: code-block

Matt Lewis wrote:

> function rand_not( integer x )
>   integer r
>   r = rand( max-1 )
>   if r >= x then r += 1 end if
>   return r
> end function
>
 Why didn't I think of that--excellent fast code.

-- Mike Nelson

new topic     » goto parent     » topic index » view message » categorize

5. Re: code-block

On Sun, 10 Sep 2000 11:43:14 -0700, Michael Nelson
<MichaelANelson at WORLDNET.ATT.NET> wrote:

>Matt Lewis wrote:
>
>> function rand_not( integer x )
>>   integer r
>>   r = rand( max-1 )
>>   if r >= x then r += 1 end if
>>   return r
>> end function
>>
> Why didn't I think of that--excellent fast code.
>
>-- Mike Nelson


I agree, very clever. On a similar note:

function anything_but(integer min, integer max, integer excluded)
    integer r
    r = rand(max-min) + min - 1
    if r = excluded then return max end if
    return r
end function

jiri

new topic     » goto parent     » topic index » view message » categorize

6. Re: code-block

How was your vacation ?
  Welcome back

new topic     » goto parent     » topic index » view message » categorize

7. Re: code-block

Bernie wrote:

>How was your vacation ?
>   Welcome back

Thanks, Bernie, overall not too bad. Mine was marred a bit by a toothache
and a cold. Everyone else was ok, they all enjoyed themselves immensely. At
my age it would probably be better to restrict myself to *virtual* skiing
only...

jiri
_________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.

Share information about yourself, create your own public profile at
http://profiles.msn.com.

new topic     » goto parent     » topic index » view message » categorize

8. Re: code-block

Thank you, all.
How does one spell that Japanese ... shibui ?
Wolf
----------
> I agree, very clever. On a similar note:
> function anything_but(integer min, integer max, integer excluded)

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu