Author 
Message 
Ted Iglehar #1 / 11

random record selection
Is there a way to populate a table with several million rows then randomly pick 1 record? I have been working with the RAND() function but it doesn't appear to be doing the trick. Any help would be greatly appreciated! Thanks

Fri, 30 Aug 2002 03:00:00 GMT 


Edward Gioj #2 / 11

random record selection
Rand() is not a bad way to go...just reseed it ocassionally with something like seconds(). This provides better randomness. Quote:
>Is there a way to populate a table with several million rows then >randomly pick 1 record? I have been working with the RAND() >function but it doesn't appear to be doing the trick. >Any help would be greatly appreciated! >Thanks

Fri, 30 Aug 2002 03:00:00 GMT 


Anders Altber #3 / 11

random record selection
Ted You can get random numbers from Rand(). Use Rand(1) to seed it with a value from the clock. * Rand(1) && fixed seed * Rand(1) && random seed store 0 to x store 1e6 to y store 0 to z for i=1 to 1e4 x= int(rand()*1e6)+1 y=min(x,y) z=max(x,z) next ?y,z You can change 1e4 to 1 or 2 or 1e6 to see the range a run would return. Anders
Quote: > Is there a way to populate a table with several million rows then > randomly pick 1 record? I have been working with the RAND() > function but it doesn't appear to be doing the trick. > Any help would be greatly appreciated! > Thanks

Fri, 30 Aug 2002 03:00:00 GMT 


Anders Altber #4 / 11

random record selection
Quote: > Rand() is not a bad way to go...just reseed it ocassionally with something > like seconds(). This provides better randomness.
> >Is there a way to populate a table with several million rows then > >randomly pick 1 record? I have been working with the RAND() > >function but it doesn't appear to be doing the trick. > >Any help would be greatly appreciated! > >Thanks

Fri, 30 Aug 2002 03:00:00 GMT 


Andy Howar #5 / 11

random record selection
Ted, Count the exact number of records in your table after filling it then have rand() select a number between one and that number, then open the record with that recno(). I would also include seconds() because the VFP rand() isn't very good. * Sent from RemarQ http://www.remarq.com The Internet's Discussion Network * The fastest and easiest way to search and participate in Usenet  Free!

Fri, 30 Aug 2002 03:00:00 GMT 


Fred Taylo #6 / 11

random record selection
In what way is the FoxPro RAND() function "not very good"? Fred
Quote: >Ted, >Count the exact number of records in your table after filling it >then have rand() select a number between one and that number, >then open the record with that recno(). I would also include >seconds() because the VFP rand() isn't very good. >* Sent from RemarQ http://www.remarq.com The Internet's Discussion Network * >The fastest and easiest way to search and participate in Usenet  Free!

Fri, 30 Aug 2002 03:00:00 GMT 


Fred Taylo #7 / 11

random record selection
All the RAND() function does is generate a pseudorandom number between 0 and 1. It's pseudo randomrandom because it is repeatable, according to the "seed" number you use to start it. For the same seed number, you will ALWAYS get the same random number sequence. So if you start the RAND() function with a seed of 1, that means to use the system clock to set the seed, therefore it's much more "random" than if you always use some constant seed, like 1, which will always generate the same sequence. If you want to get a random number between 1 and 1000, you would take random number returned from RAND() and do: CEILING(RAND()*1000) Note that the sequence you get for the RAND() function will eventually start repeating itself. That is the nature of pseudorandom number generators. I'm not really sure you can get 2,000,000 random numbers from the RAND() function, though. Fred Quote:
>I am not quite sure how to seed it with the record number and the seconds? >Let's say I have 2,000,000 records. According to the syntax I would put >x = rand(2000000) correct? >When I do that, I receive a value less than 1 which is what the syntax says >it will produce. I think I am missing something big with how this function >works? >I know I can multiply that number by 10 or 100 to receive an INT but I still >can't place a relationship on it to the original 2,000,000?
>> Ted, >> Count the exact number of records in your table after filling it >> then have rand() select a number between one and that number, >> then open the record with that recno(). I would also include >> seconds() because the VFP rand() isn't very good. >> * Sent from RemarQ http://www.remarq.com The Internet's Discussion Network >* >> The fastest and easiest way to search and participate in Usenet  Free!

Fri, 30 Aug 2002 03:00:00 GMT 


Ted Iglehar #8 / 11

random record selection
I am not quite sure how to seed it with the record number and the seconds? Let's say I have 2,000,000 records. According to the syntax I would put x = rand(2000000) correct? When I do that, I receive a value less than 1 which is what the syntax says it will produce. I think I am missing something big with how this function works? I know I can multiply that number by 10 or 100 to receive an INT but I still can't place a relationship on it to the original 2,000,000?
Quote: > Ted, > Count the exact number of records in your table after filling it > then have rand() select a number between one and that number, > then open the record with that recno(). I would also include > seconds() because the VFP rand() isn't very good. > * Sent from RemarQ http://www.remarq.com The Internet's Discussion Network * > The fastest and easiest way to search and participate in Usenet  Free!

Sat, 31 Aug 2002 03:00:00 GMT 


Anders Altber #9 / 11

random record selection
I would add to your message that if you want the widest possible range of random numbers you have to SET DECIMALS TO 18. You can get the range 1 to 2000,000, Here's a test; repeated a few times, like half a million, you would get both 1 and 2E6. set decimals to 18 for j = 1 to 10 store 0 to x store 2e6 to y store 0 to z for i=1 to 5e5 x = ceiling(rand()*2e6) y = min(x,y) z = max(x,z) next ?y,z next Anders
Quote: > All the RAND() function does is generate a pseudorandom number between 0 > and 1. It's pseudo randomrandom because it is repeatable, according to the > "seed" number you use to start it. For the same seed number, you will > ALWAYS get the same random number sequence. So if you start the RAND() > function with a seed of 1, that means to use the system clock to set the > seed, therefore it's much more "random" than if you always use some constant > seed, like 1, which will always generate the same sequence. > If you want to get a random number between 1 and 1000, you would take random > number returned from RAND() and do: CEILING(RAND()*1000) > Note that the sequence you get for the RAND() function will eventually start > repeating itself. That is the nature of pseudorandom number generators. > I'm not really sure you can get 2,000,000 random numbers from the RAND() > function, though. > Fred
> >I am not quite sure how to seed it with the record number and the seconds? > >Let's say I have 2,000,000 records. According to the syntax I would put > >x = rand(2000000) correct? > >When I do that, I receive a value less than 1 which is what the syntax says > >it will produce. I think I am missing something big with how this function > >works? > >I know I can multiply that number by 10 or 100 to receive an INT but I > still > >can't place a relationship on it to the original 2,000,000?
> >> Ted, > >> Count the exact number of records in your table after filling it > >> then have rand() select a number between one and that number, > >> then open the record with that recno(). I would also include > >> seconds() because the VFP rand() isn't very good. > >> * Sent from RemarQ http://www.remarq.com The Internet's Discussion > Network > >* > >> The fastest and easiest way to search and participate in Usenet  Free!

Sat, 31 Aug 2002 03:00:00 GMT 


Fred Taylo #10 / 11

random record selection
Thanks, Anders. I had my decimal setting at 8, but I never saw a number below 1000 (luck of the draw, I guess). I only ran 50K tests, not 500K, though. ;) Fred Quote:
>I would add to your message that if you want the widest possible range of >random numbers you have to SET DECIMALS TO 18. You can get the range 1 to >2000,000, Here's a test; repeated a few times, like half a million, you >would get both 1 and 2E6. >set decimals to 18 >for j = 1 to 10 >store 0 to x >store 2e6 to y >store 0 to z >for i=1 to 5e5 >x = ceiling(rand()*2e6) >y = min(x,y) >z = max(x,z) >next >?y,z >next >Anders
>> All the RAND() function does is generate a pseudorandom number between 0 >> and 1. It's pseudo randomrandom because it is repeatable, according to >the >> "seed" number you use to start it. For the same seed number, you will >> ALWAYS get the same random number sequence. So if you start the RAND() >> function with a seed of 1, that means to use the system clock to set the >> seed, therefore it's much more "random" than if you always use some >constant >> seed, like 1, which will always generate the same sequence. >> If you want to get a random number between 1 and 1000, you would take >random >> number returned from RAND() and do: CEILING(RAND()*1000) >> Note that the sequence you get for the RAND() function will eventually >start >> repeating itself. That is the nature of pseudorandom number generators. >> I'm not really sure you can get 2,000,000 random numbers from the RAND() >> function, though. >> Fred
>> >I am not quite sure how to seed it with the record number and the >seconds? >> >Let's say I have 2,000,000 records. According to the syntax I would put >> >x = rand(2000000) correct? >> >When I do that, I receive a value less than 1 which is what the syntax >says >> >it will produce. I think I am missing something big with how this >function >> >works? >> >I know I can multiply that number by 10 or 100 to receive an INT but I >> still >> >can't place a relationship on it to the original 2,000,000?
>> >> Ted, >> >> Count the exact number of records in your table after filling it >> >> then have rand() select a number between one and that number, >> >> then open the record with that recno(). I would also include >> >> seconds() because the VFP rand() isn't very good. >> >> * Sent from RemarQ http://www.remarq.com The Internet's Discussion >> Network >> >* >> >> The fastest and easiest way to search and participate in Usenet  Free!

Sat, 31 Aug 2002 03:00:00 GMT 


SEDLex Informatica s.r. #11 / 11

random record selection
Quote:
> I am not quite sure how to seed it with the record number and the seconds? > Let's say I have 2,000,000 records. According to the syntax I would put > x = rand(2000000) correct? > When I do that, I receive a value less than 1 which is what the syntax says > it will produce. I think I am missing something big with how this function > works? > I know I can multiply that number by 10 or 100 to receive an INT but I still > can't place a relationship on it to the original 2,000,000?
let x = random number (0<= x <=1) the relationship you need is y = 1 + INT(x * 1,999,999) if x = 0 then y = 1 if x = 1 then y = 2,000,000 Andrea Mariottini

Sun, 01 Sep 2002 03:00:00 GMT 


