Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
what does the below script do? How many iterations would it execute?
TempTable:
Load
Pick(Ceil(3*Rand()),'Standard','Premium','Discount') AS ProductType,
Pick(Ceil(6*Rand()),'Apple','Orange','Cherry','Plum','Fig', 'Pear') AS Category,
Pick(Ceil(3*Rand()),'Heavy','Medium','Light') AS Weight,
Pick(Ceil(2*Rand()),'2013','2014') AS Year,
Round(1000*Rand()*Rand()*Rand()) AS Sales,
Rand() as RandValue,
IterNo() as IterValue
Autogenerate 20
While IterNo()=1 or Rand()<=0.5; /*if I remove the where clause, it will run 20 times per the autogenerate function. Why doesn't it stop on 1st iteration since we have condition IternO()=1 */
Thanks in advance!
It doesn't necessarily stop after one iteration because you have added a second condition with the OR operator. So the while loop continues if iterno = 1 or as long as the result of rand() is smaller or equal to 0.5. So you get at least one iteration and potentially many iterations.
Iterno() starts always with 1 and will be never zero. I think I wouldn't use this kind of logic if I would want to create a random number of records between a defined min/max-value else rather playing with something like this:
...
autogenerate rangemax(rangemin(30, rand()*300), rand()*3000);
- Marcus
It doesn't necessarily stop after one iteration because you have added a second condition with the OR operator. So the while loop continues if iterno = 1 or as long as the result of rand() is smaller or equal to 0.5. So you get at least one iteration and potentially many iterations.
But in that case, I will get 20 records for 1st iterations as the IterNo() is zero.
I will have another 40 records as Iterno() is 1 irrespective of the RAND() value. So total 40 records at least because one of the condition will hold true.
The 3rd loop will generate records until the RAND() returns a value >0.5.
However, I sometime get only 30-35 records. Why is that happening? Shouldn't it be always 40+?
Iterno() starts always with 1 and will be never zero. I think I wouldn't use this kind of logic if I would want to create a random number of records between a defined min/max-value else rather playing with something like this:
...
autogenerate rangemax(rangemin(30, rand()*300), rand()*3000);
- Marcus