1. code-block
- Posted by wolfgang fritz <wolfritz at king.igs.net> Sep 10, 2000
- 417 views
... 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
2. Re: code-block
- Posted by "Darth Maul, aka Matt" <uglyfish87 at HOTMAIL.COM> Sep 10, 2000
- 393 views
function anything_but(integer x) integer i i=x while i=x do i=rand(yourmaximumhere) end while return i end function
3. Re: code-block
- Posted by Matt Lewis <matthewwalkerlewis at YAHOO.COM> Sep 10, 2000
- 401 views
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/
4. Re: code-block
- Posted by Michael Nelson <MichaelANelson at WORLDNET.ATT.NET> Sep 10, 2000
- 388 views
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
5. Re: code-block
- Posted by jiri <j.babor at GNS.CRI.NZ> Sep 10, 2000
- 380 views
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
6. Re: code-block
- Posted by Bernie <xotron at PCOM.NET> Sep 10, 2000
- 396 views
- Last edited Sep 11, 2000
How was your vacation ? Welcome back
7. Re: code-block
- Posted by jiri babor <jiri_babor at HOTMAIL.COM> Sep 11, 2000
- 388 views
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.
8. Re: code-block
- Posted by wolfgang fritz <wolfritz at king.igs.net> Sep 11, 2000
- 396 views
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)