A letter of recommendation is not just a service to the student about whom I am writing. A letter is also a service to the people who read it and use its contents to choose new students for their graduate program. In an effort to be fair to everyone, my letters will set out the objective facts at the beginning. In particular, there will be a sentence that looks like this:
I was Blank's instructor in Math mmm. He received a grade of blank, ranking k among n students.
If you did poorly in the class, this statement may not be what you want. The solution to this problem is to find a class in which you did better, and ask the relevant instructor for a letter of recommendation. You might even ask that instructor to make the objective statement above.
Generally, the instructions to letter writers ask the recommender to indicate the context in which the recomendee's work was supervised. This means that if I have not formally supervised your work, in the context of a course or independent study, I will not write a letter.
This is a state university where the ratio of students to faculty is about 30 to 1. I recognize that it may be a problem for students applying to graduate programs to find a professor who knows their work. The solution to this can be found in my advice to undergraduate math majors: figure out what you want to be doing in 5 years, then figure out what you must do now to make that happen. This means, for example, if you want to apply to a graduate program, you should plan your coursework so that you can get letters of recommendation.
The ideas here are borrowed from someone who has given me very useful advice. (I'm just not sure if he wants to be credited!)