MathGroup Archive 2007

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

Search the Archive

Re: Noob evaluation question


heycarnut schrieb:
> Thanks for all the answers!
> The example we gave was contrived, as I said, so obviously we would
> use Range[Random...]] if the example
> was doing something real!
> 
> We did of course just evaluate the random before the evaluation of the
> Position.
> 
> My question was not clear enough, I think. We were just curious if
> there was a way to keep the statement 'purely functional', and use
> something akin to hold/release to freeze the first value returned by
> the Random. The answer appears to be no, matching our initial gut
> feeling, though chris' answer comes close with using a helper function
> - familiar to us from Lisp.
> 
> Thanks again, all!
> 
> Rob
> 
> 

Hi Rob,

this is your example:

SeedRandom[1];
Position[{1, 2, 3, 4, 5, 6, 7, 8, 9}, _?(#1 <= Random[Integer, {1, 9}] & )]

--> {{1}, {2}, {3}, {5}, {6}}

And does this match your needs?

SeedRandom[1];
Function[r,
  Position[{1, 2, 3, 4, 5, 6, 7, 8, 9}, _?(#1 <= r & )]]
[Random[Integer, {1, 9}]]

--> {{1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}}

Peter


  • Prev by Date: Re: Two successive FindMinimum -> Bug?
  • Next by Date: Re: Re: SphericalPlot3D doesn't work
  • Previous by thread: Re: Noob evaluation question
  • Next by thread: [Admin] Missing Posts