-
-
Notifications
You must be signed in to change notification settings - Fork 555
Idea for new Exercise with Random Numbers #616
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I guess we just have robot-name, that mixes random string generation and persistent states, and simple-cipher, which demands the use of a randomly generated key if none is provided. |
Although dealing with randomness is a great subject, I don't necessarily think it makes for a great exercise. Part of the problem of randomness is that it often is quite hard to write tests for it. It is not uncommon to have tests fail, well, randomly! Perhaps you could further expand on how you would want the tests to look like? |
I've like a new random problem to replace robot name. It would be great if it included a way to create different kinds of serial numbers like book SKUs or different length or formats. |
That’s a good point about randomness being difficult to test for, @ErikSchierboom. In my mind I assumed that the tests would just check that the number generated was within the range that the programmer wanted it to be. So if they created a regular 6-sided dice, then the test would make sure the roll was between 1 and 6. But I do see how creating a whole exercise just for that may seem like a waste of time. I remember how confused I was when I first learned about generating random numbers, which is why I think it has the potential to be a helpful topic for new programmers. A way to make it a more in depth exercise may be to ask them to create a dice where the smallest side is not 1, so it can help show how numbers can be within a certain range. Something like this for a second type of dice:
Another option would be to have each side of the dice be multiples of a specific number, so have them create a dice where each side will have a value that is a multiple of 10. It would look something like this:
This may make the exercise more worthwhile and give the person learning some more tools to use in the future. I wrote some Unit tests that would test each of the 3 dice roll functions in these comments, and I tried to model them after the ones for other exercises on the website. I haven’t used Boost Test before so I apologize if these are sloppy or could be written better. Here they are:
Maybe there is a better object to use than a dice for this type of exercise, I just haven’t thought of one. I thought about what you said about generating SKUs, @masters3d, but I feel like that would fall into the category of generating numbers within a certain range. Or maybe there could be an exercise that covers left and right zero padding and other formatting options. Like inserting a “.” every 5 characters, having output print to a specific side of the screen, etc. I think you are onto a good idea with that! |
Cross post: #731 (comment)
|
@sleininger Are you interested in putting together this problem? See #731 |
You can test random functions either by property-based testing or by mocking the generator. For example, if the exercise is to create a Dungeons & Dragons character generator, and the dice rules for determining your character's stats are "Roll 4 six-sided dice, keep the three highest", then one property is that each character stat must be within the interval 3-18. Another property is that given three random dice I don't know how to encode this in canonical data, though. Perhaps by comments rather than specific unit test values. I don't know if all tracks support mocking a generator or property-based testing libraries. But I don't think that should be a reason to leave out exercises with randomness for languages that handle this well. As for learning goals, besides getting acquainted with your language's random generator (a huge joy), learning how to separate side effects from your core logic is something that most (imperative) languages rarely encourage you to do. So learning how to write testable, random code is a pretty cool goal, too. Still, if there are no concrete suggestions, perhaps this issue should be closed? @sleininger: I'm open to cooperate with you on creating a randomness exercise, but we need a theme. :) |
Love this idea! We can test for random numbers, but also have the system generate random names.
There is some precendence, see this test case.
I'd say go with the D&D generator. It's a really practical example that a lot of people will be familiar with I think. |
D&D stat rolling may be a good idea for a first randomness exercise, since it's just random numbers and how to isolate and test side effects. But I'd love if there were an exercise that involved generating mazes or dungeons. For mazes the testable property can be that the maze is connected a certain way (e.g. planar, or fully within a square). For dungeons the property can be that generator's size parameter is equal to the number of rooms in the dungeon. I'll submit a PR to the D&D idea on Monday. :) |
Sounds interesting. May be a good follow up exercise from the D&D one. |
This issue can be closed as it resulted in the additional of the dnd-character exercise, which focuses on random number generation. |
Hello,
I'm very new to this project, and have a lot more exploring to do. But I love what exercism does, and plan on using it to better myself in the future. I am also appreciative that you are welcoming to new contributors.
I am a CS student and consider myself to be pretty new to development. I was looking through the available exercises in languages I'm familiar with, and didn't notice any that used random numbers, which was something valuable I learned about in my intro classes. We made programs to simulate rolling dice, and I'll attach one I made in C++.
It asks the user for the number of dice they'd like to roll, number of faces each dice should have, and how many times they'd like to roll. This would give someone experience with nested for loops and with generating random numbers, and is a very simple program for a beginner.
So in the ReadMe it would ask the student to create a program the simulates rolling dice. It should get the number of dice, number of faces, and number of rolls from the user. Then it should display the randomized results for each dice for the user.
I hope this is the correct place for suggestions like this. Thank you!
The text was updated successfully, but these errors were encountered: