Re: question: what does this "fix" thingy here do? r=fix(rnd*6)+1

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Guy Cohen (support_at_mcam2u.com)
Date: 05/17/04


Date: Mon, 17 May 2004 12:33:05 +0200

Very simple

It returns the fixed part of a real number
U can use int(number) if you like Int better.

?rnd*6
 4.233285
?fix(4.23)
 4

Got it ?
Guy
??"allan go" <allanygo1108@yahoo.com> ??? ??????
news:en%23sPB$OEHA.2924@TK2MSFTNGP10.phx.gbl...
> HELP pls!
>
> what does this fix text here do?
> r=fix(rnd*6)+1
>
> thanks!
>
>
>
>
> "Re: Exclude number from RND
> From: Bob Butler
> Date Posted: 12/17/2003 7:46:00 AM
>
>
>
> "Don" <dsarvas@yahoo.com> wrote in message
> news:3fe06561.15284379@news.west.cox.net
> > Randomize
> > for i = 1 to 6
> > TRYAGAIN:
> > IntNumber(i) = Int((6 * Rnd) + 1)
> > For intPrev = 1 To i - 1
> > If intNumber(intPrev) = IntNumber(i) Then
> > GoTo TRYAGAIN
> > End If
> > Next intPrev
> > next i
> >
>
> You don't want to be using GoTo, especially to jump out of a loop like
> that.
> That sort of coding quickly leads to "spaghetti" code that is very
> difficult
> to maintain. One way to avoid it would be to use another array to store
> what has been picked:
>
> Dim picked(1 to 6) as long
> Dim numbers(1 to 6) as long
> dim i as long
> dim r as long
> randomize ' only do this once in the application
> for i=1 to 6
> r=fix(rnd*6)+1
> do until picked(r)=0
> r=fix(rnd*6)+1
> loop
> picked(r)=i
> numbers(i)=r
> next
>
> In general, I'd use the technique of filling an array with the values
> 1-6
> and then randomly shuffling the array. With a range of 6 values the
> above
> method works OK but if you were picking 1-100 or 1-1000 it could take a
> long
> time before it happens to pick the last few numbers.
>
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!



Relevant Pages

  • Re: Generate list of unique random integer values?
    ... Give it an array of elements and it will put them in random order and return the randomized elements back in the original array that was passed to it. ... Dim RandomIndex As Long ... The neat thing is, if you pass an already randomized array to this routine, those randomly ordered elements will be randomize -- sort of like shuffling an already shuffled deck of cards. ...
    (microsoft.public.vb.general.discussion)
  • Re: Get last record of recordset that holds data
    ... Simplified as rs.GetRows will give a transposed array, ... but looks to me it is better to loop through columns in the ... Dim r As Long ... Dim lCycles As Long ...
    (microsoft.public.data.ado)
  • Re: Get last record of recordset that holds data
    ... no matter what the data is in the array. ... If the number of rows that have to be checked before encountering a non-null value is less than the number of columns, then yes, the collection of columns is the larger collection and should be in the outer loop. ... Dim r As Long ... Dim lCycles As Long ...
    (microsoft.public.data.ado)
  • Re: In excel, I want to generate a random number
    ... elements back in the original array that was passed to it. ... the Randomize statement one time only. ... Dim RandomIndex As Long ... cards such as 3 of Hearts (here your DeckOfCards is declared as a String: ...
    (microsoft.public.excel.misc)
  • Re: Scope of the arrays in Loops
    ... > Dim stAs Variant 'Integer ... > ' end of check for clash ... > In the do while loop i am storing the time values and later after the ... > array stand et. ...
    (microsoft.public.excel.programming)