# changing intervals in do loops

I have a main program whose structure has Do loop and changing that to Table form is not easy at this stage. I want to have dense data in the interval [0.8, 1.2, 0.01], Although the normal data in the interval of [0,0.8) and (1.2,2] is 0.1.

test = {};

Do[
RandomSeed[1]; test0 = RandomReal[]; AppendTo[test, {i, test0}]
, {i, 0, 2, 0.1}]

=================

You want this for both i and j?
– JasonB
Feb 26 at 10:14

So sorry, there is just one loop
– Irreversible
Feb 26 at 10:17

=================

1

=================

Make a list of the numbers you want to iterate over by catenating 3 Range calls,

iteratelist =
Catenate[{Range[0, 0.79, .1], Range[0.8, 1.2, 0.01],
Range[1.3, 2, .1]}]
(* {0., 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.81, 0.82,
0.83, 0.84, 0.85, 0.86, 0.87, 0.88, 0.89, 0.9, 0.91, 0.92, 0.93,
0.94, 0.95, 0.96, 0.97, 0.98, 0.99, 1., 1.01, 1.02, 1.03, 1.04, 1.05,
1.06, 1.07, 1.08, 1.09, 1.1, 1.11, 1.12, 1.13, 1.14, 1.15, 1.16,
1.17, 1.18, 1.19, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.} *)

test = {};

Do[RandomSeed[1];
test0 = RandomReal[];
AppendTo[test, {i, test0}], {i, iteratelist}]

In case you were unaware, AppendTo is horribly inefficient, and if possible you should always use Reap and Sow instead. For example this code

test = Reap[
Do[
test0 = RandomReal[];
Sow[{i, test0}];
, {i, iteratelist}]
][[2, 1]]

is about 50 times faster than the AppendTo example above

Yes, I had seen Reap and Sow but I have not worked with them unfortunately
– Irreversible
Feb 26 at 10:26