Thanks, that works very well and is a lot faster than involving a table. I don't need the x output, so I have done:
with conf(max) as (select 10000), rnd(n, x) as (select abs(random() %(1000 - 100)) + 100, 1 union all select abs(random() %(1000 - 100)) + 100, x + 1 from rnd where x < (select max from conf)) select n from rnd Not familiar with CTE's and it looks quite complex. RBS On Fri, Jan 22, 2016 at 11:22 AM, Stephan Beal <sgbeal at googlemail.com> wrote: > On Fri, Jan 22, 2016 at 12:11 PM, Bart Smissaert <bart.smissaert at gmail.com > > > wrote: > > > Say I want 10000 random numbers between 100 and 1000 how can I do that > > without > > selecting from a table? > > I know I can do: > > select abs(random() %(1000 - 100)) + 100 as rnd from TableWith10000Rows > > but there must be a better way. > > > > > Maybe not perfect, but this seems to work... > > sqlite> with conf(max) as (select 10), rnd(n, x) as (select abs(random() > %(1000 - 100)) + 100, 1 union all select abs(random() %(1000 - 100)) + 100, > x+1 from rnd where x<(select max from conf)) select * from rnd; > 668|1 > 301|2 > 619|3 > 380|4 > 412|5 > 263|6 > 563|7 > 877|8 > 573|9 > 468|10 > > just swap out the 'conf' part with 1000. > > > > -- > ----- stephan beal > http://wanderinghorse.net/home/stephan/ > http://gplus.to/sgbeal > "Freedom is sloppy. But since tyranny's the only guaranteed byproduct of > those who insist on a perfect world, freedom will have to do." -- Bigby > Wolf > _______________________________________________ > sqlite-users mailing list > sqlite-users at mailinglists.sqlite.org > http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users >