Maybe this will help:
The functions I have designed are not to be called once to generate aq group of n records up to a max range.
So just run the code of my previous post and see what you get there.
You make ONE call and get 5 numbers. Shouldn't this clear up what the parameters mean?
In the first parameter you pass in the array the function should populate, in the second parameter you specify how many different numbers you want, and in contrast to a normal random number generated they will guaranteed to be different, non repeating. But this can also only be assured, because they are not generated separately, one per call, but all numbers are generated in a single call. That, by the way, was also done by your own function.
Thinking of a function generating 5 values, in each in 5 calls without being signalled when to start the series isn't possible, I already told you that, and that's not a question of the programming language.
Now, since VFP can't RETURN r1,r2,r3,r4,r5, as Python could, the only way to return 5 values at once is using a cursor or array. Your function used a cursor, my last one now uses an array.
So the loop determining 5 field names should be like this:
Code:
Local array laRandnumbers[5]
Local lnCounter
Randomize3(@laRandnumbers,5,30)
SELECT yourtable
For lnCounter = 1 to 5
? FIELD( laRandnumbers[lnCounter])
EndFor
And again, and I already repeatedly said so, when your 30 fields don't start at field number 1, then add an offset to this. I remember you have tow fields before you series of 30 or 31 fields, so add an offset of 2 to skip those two fields not belonging to the "calender" columns.
Code:
Local array laRandnumbers[5]
Local lnCounter, lnHowManyDifferentNumbers, lnNumberRandeFrom1ToThis
lnHowManyDifferentNumbers = 5
lnNumberRandeFrom1ToThis = 30
Randomize3(@laRandnumbers, lnHowManyDifferentNumbers ,lnNumberRandeFrom1ToThis )
Local lnFieldNumberOffset
lnFieldNumberOffset = 2 && add to all laRandnumbers elements to shift the range from 1...lnNumberRandeFrom1ToThis to 1+lnFieldNumberOffset...lnNumberRandeFrom1ToThis+lnFieldNumberOffset
* for example to change from 1...30 to 3..32 add 2
SELECT yourtable
For lnCounter = 1 to lnHowManyDifferentNumbers
lnFieldnumber = laRandnumbers[lnCounter] + lnFieldNumberOffset
? FIELD(lnFieldnumber)
EndFor
I can't give you exactly what you need, for example, whether you want to cover the range 1..30 or whether that will depend on the number of days the current month has, that's up to you. But it's all adjustable.
Bye, Olsf.
Olaf Doschke Software Engineering