MathGroup Archive 2006

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

Search the Archive

Re: number not fitting in

  • To: mathgroup at smc.vnet.net
  • Subject: [mg71567] Re: number not fitting in
  • From: Bill Rowe <readnewsciv at sbcglobal.net>
  • Date: Thu, 23 Nov 2006 05:41:38 -0500 (EST)

On 11/22/06 at 5:22 AM, JGBoone at gmail.com wrote:

>First let me say that i am new to this mathematica and programming
>business. I am programming a random speciation. I have a list, lyst,
>that is a certain range. I want to replace, at random, one part of
>lyst with something that is not in the original list, speciation.
>When I table this, it puts the speciation outside the list and
>inside the list. Can anyone help me? here's the line that seems to
>be giving me trouble.

It isn't really clear to me what you want to do. I don't 
understand, "when I table this, it puts the speciation outside 
the list and inside the list.

>Can anyone help me? here's the line that seems to be giving me trouble.

>lyst[[Random[Integer, {1, Length[lyst]}]]] = Random[Integer,
>{Length[lyst]+ 1,Length[lyst] + 100}]

You don't really say what you mean by trouble. The line above 
appears to be valid Mathematica syntax. And when I do:

In[1]:=
lyst=Range@5

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

lyst[[Random[Integer,{1,Length[lyst]}]]]=
         Random[Integer,{Length[lyst]+1,Length[lyst]+100}]

Out[2]=
17

In[3]:=
lyst

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

it appears to me it is working correctly. I would have coded 
this a bit differently as follows:

lyst[[Random[Integer,{1,Length[lyst]}]]]=
         Random[Integer,{1,100}]+Length[lyst]

simply to reduce the amount of typing and the number of times 
Length[lyst] is called. Also, to me, the resulting code is 
clearer. But I don't see this as addressing your problem.
--
To reply via email subtract one hundred and four


  • Prev by Date: Re: number not fitting in
  • Next by Date: StringReplace with empty list (Mathematica wish list)
  • Previous by thread: Re: number not fitting in
  • Next by thread: Elementary workbench question