MathGroup Archive 2008

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

Search the Archive

Re: need help

  • To: mathgroup at smc.vnet.net
  • Subject: [mg87330] Re: [mg87308] need help
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Tue, 8 Apr 2008 05:34:29 -0400 (EDT)
  • Reply-to: hanlonr at cox.net

ri = RandomInteger[{-100, 100}, 10]

{-19,-96,85,-6,-60,-21,40,78,-4,-82}

ri[[RandomInteger[Length[ri]]]]

78

sumf[x_Integer] := FindInstance[
   a^2 + b^2 + c^2 + d^2 == x, {a, b, c, d}, Integers][[1]]

sumf /@ {1, 4, 7}

{{a->0,b->0,c->1,d->0},{a->0,b->0,c->2,d->0},{a->1,b->1,c->2,d->1}}


Bob Hanlon

---- haitomi <tpnycity at yahoo.com> wrote: 
> Hello All,
> 
> I need help with two pure functions
> 
> 1)  Li[Ranlist,x] that return a list of x element selected at random from Ranlist.  (Is there any way to gennerate random from Ranlist? For example I have RanList=Range[-100,100])
> 
> 2) the function 4Sumf[x] is computing the sum of 4 squares of x. If I have x=1, this function will gennerate 1^2+0^2+0^2+0^2, if x=4 then 2^2+0^2+0^2+0^2, if x=7 then 2^2+1^2+1^2+1^2
> 
> Is anyone out there have any ideas?
> Thanks All,
> Tomi
> 



  • Prev by Date: Just primitive ColorFunction
  • Next by Date: Re: need help
  • Previous by thread: need help
  • Next by thread: Re: need help