Jump to content

- - - - -

Classpad Programming - Random Integers

  • Please log in to reply
3 replies to this topic

#1 mintsmike


    Casio Freak

  • Members
  • PipPipPipPip
  • 115 posts
  • Gender:Male
  • Location:Great Britain

  • Calculators:
    fx-5500L, fx-991ES,fx-9860SD (with GII SD OS), Casio Classpad 330, MS Windows Calc, Ubuntu Calc, a Hammer and my Brain!

Posted 04 May 2009 - 09:36 AM

Hello folks,

I have recently started to program Addins for the ClassPad. I can use the SDK software to the extent that I can understand the basic principles and create my own program to output simple text on the screen.

I need to create a random integer and assign it to an integer variable. Now, I would usually do this with the C++ Standard Library using

#include <cstdlib>
#include <iostream>

but I have tried this and such file is not recognised by the SDK compiler.

If there is some ClassPad specific method to get a random/pseudo-random integer then I would be grateful for it.


Edited by mintsmike, 04 May 2009 - 09:38 AM.

#2 Kilburn


    Casio Technician

  • Members
  • PipPipPipPipPipPip
  • 491 posts
  • Gender:Male
  • Location:France
  • Interests:Blah

  • Calculators:
    FX-7500 G
    ClassPad 300

Posted 04 May 2009 - 11:22 AM

You have to include <stdlib.h>, not <cstdlib> or <stdlib>, which don't exist, and then use the rand() function. If I remember correctly, it returns a random integer between 0 and 65535 or so, so you can use the modulo operator % if you want to get a smaller number. For instance, rand()%8 will return a number between 0 and 7.

Also, the functions from stdio.h and iostream.h work only on the PC, not on the ClassPad. If you want quick output, you'll have to use a special stream called CPDump, from ClassPad.h. It works a bit like cout, have a look at the DebugExample example add-in. The only constraint is that you need to have at least a CPMainFrame and a CPModuleWindow set up in PegAppInitialize, else it will crash.

#3 Guest_Fibbit_*

  • Guests

Posted 21 September 2009 - 12:02 PM

dude, to get a random number type:

#include <time.h>


int num;

srand ( time (NULL) );
num = (rand() %100) + 1;


printf("RANDOM NUMBER - %d", num);


#4 Guest_Fibbit_*

  • Guests

Posted 21 September 2009 - 12:03 PM

also, the reason you shouldnt use just rand() is because it will return the same random numbers each time. so its not really random.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users