pebble
  • Tutorials
  • Get the SDK
  • Guides
  • Documentation
  • PebbleOS
  • Mobile App
  • Examples
  • Index 01
  • Community
  • Blog
  • More
Privacy
Cookies
Publish

Pebble C API

  • Pebble C API
  • Moddable API (Alloy)
  • PebbleKit JS
  • PebbleKit iOS
  • PebbleKit Android
  • Foundation
    • Alloy
    • App
    • App Communication
    • App Glance
    • AppMessage
    • AppSync
    • AppWorker
    • DataLogging
    • DataStructures
      • UUID
    • Dictation
    • Dictionary
    • Event Service
      • AccelerometerService
      • AlarmService
      • AppFocusService
      • BacklightService
      • BatteryStateService
      • CompassService
      • ConnectionService
      • HealthService
      • TickTimerService
      • TouchService
    • Exit Reason
    • Internationalization
    • Launch Reason
    • Logging
    • Math
    • Memory Management
    • Platform
    • Resources
      • File Formats
    • Storage
    • Timer
    • Wakeup
    • Wall Time
    • WatchInfo
  • Graphics
    • Draw Commands
    • Drawing Paths
    • Drawing Primitives
    • Drawing Text
    • Fonts
    • Graphics Context
    • Graphics Types
      • Color Definitions
  • User Interface
    • Animation
      • PropertyAnimation
    • Clicks
    • Gesture Recognizers
    • Layers
      • ActionBarLayer
      • BitmapLayer
      • MenuLayer
      • RotBitmapLayer
      • ScrollLayer
      • SimpleMenuLayer
      • StatusBarLayer
      • TextLayer
    • Light
    • Preferences
    • Speaker
    • UnobstructedArea
    • Vibes
    • Window
      • ActionMenu
      • NumberWindow
    • Window Stack
  • Worker
  • Standard C
    • Format
    • Locale
    • Math
    • Memory
    • String
    • Time

Math

Standard math functions.

Function Documentation

int rand()

Generate a pseudo-random integer between 0 and RAND_MAX inclusive.

This function can be seeded by srand().

A simple way to change the range to be an integer between 0 and n-1 inclusive is using % e.g. rand() % n.

Returns

The pseudo-randomly generated number

void srand(unsigned int seed)

Seed the pseudo-random number generator.

When your app starts, the pseudo-random number generator is automatically seeded with a random number that is generated by a high-entropy hardware random number generator.

This function affects subsequent calls to rand() to produce a sequence of numbers for a given seed value. You can use this to either create a different sequence of numbers by always using a different seed or to obtain the same sequence of numbers by reusing the same seed.

Parameters

seed

The source number used to generate a sequence of pseudo-random numbers

Macro Definition Documentation

#define RAND_MAX

The maximum integer value rand() may return.

Need some help?

Functions

  • rand
  • srand

Macro Defintions

  • RAND_MAX

Getting Help

Do you have questions about the Pebble SDK?

Do you need some help understanding something on this page?

Ask on the developer forum.