Funções "RANDOM" não funcionam!

Funções "RANDOM" não funcionam!

Postby Ladinilson » Fri Aug 07, 2020 1:41 pm

Fiz vários testes com nRANDOM(), RANDOM(), HB_RandomInt(), etc e todas elas NÃO FUNCIONARAM nas suas totalidades ou seja, todas deixaram de fornecer alguns números em uma de range 999999 e estou com muita dificuldade em encontrar uma solução para isso já que em se tratando de sorteios, nenhum número pode faltar ou se repetir.

Algum de vocês tem alguma rotina própria criada para esta função que eu consiga testar?

Obrigado
Ladinilson
 
Posts: 17
Joined: Wed Feb 04, 2009 9:38 pm

Re: Funções "RANDOM" não funcionam!

Postby nageswaragunupudi » Fri Aug 07, 2020 1:59 pm

todas elas NÃO FUNCIONARAM nas suas totalidades

Your expectation is wrong.
All the above functions do what they are expected to do.
We can not expect that random number generators generate "every" number in a series. Also they may generate duplicates.

It is for us (the programmer) to use the random function to get what we want.

For example, if we want a function to generate every number between 1 to 999 without repeating then we can try this approach.

Code: Select all  Expand view

function RandomList

   local aList    := Array( 999 )
   local nAt, aRandom := {}

   AEval( aList, { |u,i| aList[ i ] := i } )

   do while Len( aList ) > 0
      nAt      := HB_RandomInt( 1, Len( aList ) )
      AAdd( aRandom, aList[ nAt ] )
      ADel( aList, nAt, .t. )
   enddo

   XBROWSER aRandom SHOW RECID

return nil
 


This function gives a list of randomly generated list of numbers from 1 to 999 without repeating and covering all numbers.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10248
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Funções "RANDOM" não funcionam!

Postby Ladinilson » Fri Aug 07, 2020 2:04 pm

Obrigado!

irei testar.
Ladinilson
 
Posts: 17
Joined: Wed Feb 04, 2009 9:38 pm

Re: Funções "RANDOM" não funcionam!

Postby Ladinilson » Fri Aug 07, 2020 2:18 pm

Para 999999 não funcionou infelizmente pois tem o uso e já testado HB_RandomInt()

:(
Ladinilson
 
Posts: 17
Joined: Wed Feb 04, 2009 9:38 pm

Re: Funções "RANDOM" não funcionam!

Postby Ladinilson » Fri Aug 07, 2020 3:11 pm

Fiz uma pequena mudança e funcionou!

Obrigado meu caro
Ladinilson
 
Posts: 17
Joined: Wed Feb 04, 2009 9:38 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 87 guests