I'm newbie in the F#, too.

Nevertheless, I can see that your code isn't clear for understanding.

Some questions, important to further answer:

  1. What is starting value of r?
  2. Has Game1 or Game1.m_Random or Game1.m_Random.Next some side-effects?

It is possible to unthinking translate this to F#, using mutables, but the translated code will look really awful from functional point-of-view.

By on 4/19/2011 11:28 PM ()

Hi,

The full version method is -

1
2
3
4
5
6
7
8
int r = 0;

while (r % 2 == 0) 
{
   r = Game1.m_Random.Next(1,7);
}

m_fAngle=MathHelper.ToRadians(r * 45);

I'm just trying to get a random number between 1 and 7 and use it to create an angle. The problem I have is the while bit, I have no doubt my code will be bad from a functional point of view at the minute but I'm just trying to get to grips with the syntax

By on 4/20/2011 2:27 AM ()

If so, then let's do...

1
2
3
4
let mutable r=0

while r % 0 = 0 do
    r <- Game1.m_Random.Next(1,7)
By on 4/20/2011 2:48 AM ()

I guess you mean -

while r % 2 = 0 as 0 = 0 is a divide by 0 :)

Yes that worked! thank you very very much :)

By on 4/20/2011 4:21 AM ()

of course, sorry :)

By on 4/20/2011 4:36 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper