2007 03 01

Tomorrow I am asking my Computer Science & Engineering students to solve this small programming problem:
Write a function in C which returns a random integer between 1 and 20. One extremely important caracteristic of the function is that it must return a different integer each time it is called. This, obviously, implies that it can only be called twenty times.
There is a second part (and in my opinion it is the coolest part):
Write the same function using a more modern programming language (e.g. Ruby).
Care to give this a go?
(Image courtesy of Sega Japan)
Popularity: 1% [?]
Add comments



March 1st, 2007 at 22:17
thxs to this quiz im motivated to do some programing again after some months of rest
need to try the cool part now…
March 2nd, 2007 at 06:56
Indeed Ruby seems very nice & Cool
was playing with http://tryruby.hobix.com/
dwl just completed
need to learn how to use it in class now…
March 4th, 2007 at 03:10
http://tryruby.hobix.com/
mone deza try sa… li interessant..mais ti tro paresse pu contigne learn Ruby la
lol
March 4th, 2007 at 10:01
Paresse?
How old are you?
March 4th, 2007 at 11:51
De nos jours, nous avons tendance à dire « La paresse est une vertu » au dépend de « La paresse est la mère de tout les vices » lol
…du moins c’est ce que je pense
Quote somewhere : « Comme la paresse est une vertu en informatique et que… »
On ne peut donc que de s’en réjouir
March 4th, 2007 at 16:38
Anyone has written something cool?
March 5th, 2007 at 01:37
wait. different from the previous number returned only. or different from all the the numbers ever returned.
If the first, any random number from 1-20 will do
but for the second, we’ll need to keep track of all numbers returned.
off topic. i got this up and running: http://blog.nbnakama.com/ it still reeks of new…
March 5th, 2007 at 09:05
Different from all the numbers ever returned of course
March 5th, 2007 at 18:13
pretty simple…
the only difficult part is to write a program in O(1) :s
March 5th, 2007 at 22:12
is it a good thing that i put the code on my blog??
March 5th, 2007 at 22:28
Hi Sundeep,
You are free to put YOUR program anywhere you like
March 18th, 2007 at 22:47
The program in o(1) was also pretty simple.(check my blog for my code)
Still,I,m trying to enhance further without using the rand() funtion but still using the same algorithm(That should be interesting)
March 18th, 2007 at 23:21
Congratulations Adarsh. Your algorithm works really well. Have you had a look at the metaprogramming part?
March 19th, 2007 at 07:36
I am working on that but not yet finished(just started).However,I’ve finishing modifying the previous version i.e not using the rand() function to generate random number but still using the same algorithm.
I’ve already posted the new version.