All,
I have a column of timestamps (c3: cx) in the following format (h:mm:ss AM/PM).
I would simply like to randomize the seconds section of each stamp via a macro and simply cannot fathom it out...please help!!
Regards,
Skyping
All,
I have a column of timestamps (c3: cx) in the following format (h:mm:ss AM/PM).
I would simply like to randomize the seconds section of each stamp via a macro and simply cannot fathom it out...please help!!
Regards,
Skyping
Last edited by skyping; 01-04-2015 at 12:04 PM.
try:Please Login or Register to view this content.
Best Regards,
Kaper
Hi,
Try this code :
RegardsPlease Login or Register to view this content.
Last edited by karedog; 01-04-2015 at 11:07 AM.
1. I care dog
2. I am a loop maniac
3. Forum rules link : Click here
3.33. Don't forget to mark the thread as solved, this is important
hi karedog,
it is not needed to initialize pseudo-random generator before each call of Rnd.
Last edited by Kaper; 01-04-2015 at 11:24 AM. Reason: deleted info on days vs. seconds as it has been changed in the code
Hi Kaper,
It is just a good practice (but probably not needed for this case), as Microsoft says :
Because the Random statement and the Rnd function start with a seed value and generate numbers that fall within a finite range, the results may be predictable by someone who knows the algorithm used to generate them.
http://msdn.microsoft.com/en-us/libr...=vs.90%29.aspx
BTW, your code only change the seconds only to 0 or 1, is this expected ?
Regards
Thank you all for your input. I have used karedogs code, but appreciate both your help.
SOLVED
You are welcome, glad I can help.
Regards
Just one further question.....how would I randomize the last minute in the above scenario....e.g. h:mm:ss AM/PMh:mm:ss AM/PM goes to h:mX:ss AM/PM ?
Thanks
Skyping.
You can use this code :
RegardsPlease Login or Register to view this content.
@karedog: "code only change the seconds only to 0 or 1, is this expected ?"
So we have a tie here, because your first code (before editing) changed whole day :-D
But it's not the main point to write. I'd like to discuss randomize a bit further.
It is wise to use it, and you probably noticed, that I used it too, but outside of the loop.
But Randomize without parameter uses (I think) system clock as a seed value. So data series generated with periodical initialisation would be "less randomly" distributed than initialized only once.
Have a look into sample file - there are 10000 numbers generated with randomize before each rnd and 10000 just one randomize at the beginning.
Have a look at the difference in frequency of different values generated by both approaches.
I'm not statistician, but anyway densities (frequencies) of numbers generated with repeated randomize are at least surprisingly located.
And it's not just one run result - call test procedure and next (different but again strange) set will be generated. If you examine only a small subsample (say 100) it's not clearly visible. but larger datasets are by no means berrer randomized by repeating randomize ;-).
Last edited by Kaper; 01-07-2015 at 08:45 AM.
Thank you once again Karedog...work great!!!
You are welcome Skyping, many thanks for the rep. points too.
Ok Kaper, it's a draw then mrgreen.gif
Well, I'm not a statistic guy either, so I cannot comment about your work, whether the data is "more random" or "same random" or something else, sorry about this.But it's not the main point to write. I'd like to discuss randomize a bit further.
It is wise to use it, and you probably noticed, that I used it too, but outside of the loop.
But Randomize without parameter uses (I think) system clock as a seed value. So data series generated with periodical initialisation would be "less randomly" distributed than initialized only once.
Have a look into sample file - there are 10000 numbers generated with randomize before each rnd and 10000 just one randomize at the beginning.
Have a look at the difference in frequency of different values generated by both approaches.
I'm not statistician, but anyway densities (frequencies) of numbers generated with repeated randomize are at least surprisingly located.
And it's not just one run result - call test procedure and next (different but again strange) set will be generated. If you examine only a small subsample (say 100) it's not clearly visible. but larger datasets are by no means berrer randomized by repeating randomize ;-).
Regards
You marked this thread as "solved", but none of the suggestions does what you ask. Try the following:
The code assumes the cells are formatted as you want.Please Login or Register to view this content.
Since Rnd returns a non-integer between 0 and less than 1, this adds random fractional seconds less than 1 instead of whole seconds.
Although this adds fractional minutes (and less than 10 minutes in the second case), which are seconds, the result includes fractional seconds. For example, if Rnd returns 0.1234, Rnd/1440 adds about 7.404 seconds. I suspect "skyping" wants random whole seconds. The fractional seconds might screw up the way he uses the random times.
Moreover, both methods add random time instead of just inserting random seconds. Consequently, they have the potential of changing the minute (minute "decade" in the second case) and hour, which does not seem to be "skyping's" intent.
Last edited by joeu2004; 01-08-2015 at 08:10 PM. Reason: cosmetic
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks