MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Noob evaluation question


Using Robby Villegas' trap method:

helpABuddy = True;
Unprotect@Position;
g_Position /; helpABuddy := Block[{helpABuddy = False, buddy`random =
     Random[Integer, {1, 9}]}, g]

In[4]:=
Position[{1,2,3,4,5,6,7,8,9},_?(#\[LessEqual]buddy`random&)]
Position[{1,2,3,4,5,6,7,8,9},_?(#\[LessEqual]buddy`random&)]
Position[{1,2,3,4,5,6,7,8,9},_?(#\[LessEqual]buddy`random&)]

Out[4]=
{{1},{2},{3},{4},{5},{6},{7},{8},{9}}

Out[5]=
{{1},{2}}

Out[6]=
{{1},{2},{3},{4},{5}}

On 3/12/07, heycarnut <heycarnut at gmail.com> wrote:
> Hi -
>
> Helping a buddy out with a small application, and I'm drawing a blank
> on the following.
>
> Given :
>
>    Position[{1, 2, 3, 4, 5, 6, 7, 8, 9}, _?(# <= Random[Integer, {1,
> 9}] &)]
>
> How can we make the generated random number 'fixed' for the evaluation
> of Position, instead of a new number getting generated at each element
> of the list (the above is a simplified and contrived example.)
>
> Thanks
> Rob
>
>
>


-- 
http://chris.chiasson.name/


  • Prev by Date: Re: beginner plot function with parameter
  • Next by Date: Re: Re: Multi-core Support in Mathematica 5.2
  • Previous by thread: Noob evaluation question
  • Next by thread: Re: Noob evaluation question