Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #13924

Table with condition

From Šerých Jakub <Serych@panska.cz>
Newsgroups comp.soft-sys.math.mathematica
Subject Table with condition
Date 2013-03-25 03:23 +0000
Message-ID <kiofvf$3bu$1@smc.vnet.net> (permalink)
Organization Time-Warner Telecom

Show all headers | View raw


Dear mathgroup,
I need to start creating list and continue until some condition is not met.  For example to generate list of random numbers until the value is not 5. Yes, it is theoreticaly possible to generate list with sufficient length, and cut it on the right place afterwords, but it is very inefficient way if the computation is much harder than just generation of random numbers.

TakeWhile[Table[RandomInteger[{0, 10}], {15}], # != 5 &]

Using the while cycle is the other way, but I can only print values using that method, but I don't know, how to generate classical list:

r = 0;
While[r != 5, r = RandomInteger[{0, 10}]; Print[r]] 

What is the right solution of such a simple problem?

Thanks in advance for any help

Jakub
 

Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread


Thread

Table with condition Šerých Jakub <Serych@panska.cz> - 2013-03-25 03:23 +0000

csiph-web