Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Randomization

Status
Not open for further replies.

TiCi

Programmer
Dec 23, 2003
11
0
0
ID
hello..

i've got a problem when i want to pull some random records from a table.. well. it is randomize.. but the problem is.. it's always random in the same sequences.. like example it's always take the records number 9, 6, 10, 3, 8... and so on.. and it's always exactly the same sequences..

this is the coding that i use to randomize the records..

********************************************
SELECT quiz
DO WHILE NOT nRandom=vmisc.jmlsoal
nRandom=nRandom+1
SELECT quiz
nRecord = ROUND(1+(FLOOR(RAND() * RECCOUNT())), 0)
GOTO nRecord
SELECT jawab
LOCATE FOR quiz.id_soal = jawab.id_soal
IF FOUND()
nRandom = nRandom - 1
ELSE
GOTO nRecord IN quiz
SELECT jawab
APPEND BLANK
REPLACE jawab.id_soal WITH quiz.id_soal
REPLACE jawab.soal_quiz WITH quiz.soal_quiz
REPLACE jawab.gambar_soal WITH quiz.gambar_soal
REPLACE jawab.jawaban WITH quiz.jawaban
ENDIF
ENDDO

********************************************

i'm using vfp 8.. and when i use rand() every first time i start vfp 8, it's always shows the same sequences..
now, how will i randomize the records without having the same sequences..
could a SYS(2015) help me?? and what is the best way to use it..

thankyou very, very much for your attention guys..
 
From memory I think issuing RAND(0) at the begining of your randomising sequence gives you a genuine random sequence.
Hope this helps
Keith
 
From the help file

To achieve the most random sequence of numbers, issue RAND( ) initially with a negative argument and then issue RAND( ) without an argument.

don't know if that will help but good luck

Ralph
 
Thankyou Guys.. but i already found it..
i'm using sys(2015) like this...

rand(asc(substr(sys(2015))))

but i'll try your sggestion to..

thanks for your reply guys...
 
I usually use

Code:
lnDesiredCnt = 10

select top lnDesiredCnt rand()+.00000000,* from MyTable order by 1

Brian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top