Re: question: what does this "fix" thingy here do? r=fix(rnd*6)+1
From: Guy Cohen (support_at_mcam2u.com)
Date: 05/17/04
- Next message: Hapticz: "Re: loop through all RGB values"
- Previous message: Hapticz: "Re: How come the FileSystemObject doesn't work?"
- In reply to: allan go: "question: what does this "fix" thingy here do? r=fix(rnd*6)+1"
- Next in thread: J French: "Re: question: what does this "fix" thingy here do? r=fix(rnd*6)+1"
- Reply: J French: "Re: question: what does this "fix" thingy here do? r=fix(rnd*6)+1"
- Messages sorted by: [ date ] [ thread ]
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!
- Next message: Hapticz: "Re: loop through all RGB values"
- Previous message: Hapticz: "Re: How come the FileSystemObject doesn't work?"
- In reply to: allan go: "question: what does this "fix" thingy here do? r=fix(rnd*6)+1"
- Next in thread: J French: "Re: question: what does this "fix" thingy here do? r=fix(rnd*6)+1"
- Reply: J French: "Re: question: what does this "fix" thingy here do? r=fix(rnd*6)+1"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|