buy hot The Fixer cool video Year One download Kasabian album nice Terminator Salvation hit cool track Jordin Sparks USA Whatever Works video download Check My Brain melodies nice video Finding Nemo nice Pop - Various Artists hit cheap DIVX Year One

digital-diy.com

Swordfish Library - RandGen Print E-mail
( 0 Votes )
  
Saturday, 04 April 2009 09:37

save_f21 Download the library: RandGen

 

This module implements a simple modulo-based PSEUDO Random Number Generator for Swordfish Basic. It's difficult to generate true random numbers from a deterministic machine like PIC. Hopefully, some mathematical methods let us have a series of numbers that seems really random, although they have all a fixed cycle upon which they restart to give the same series of values. this is why they are all called Pseudo random number generators. The cycling behaviour has the advantage to give you the possibility to repeat the same experience despite the fact that it's based on (pseudo) random numbers.

 

Usage example


Call the RandGen.Initialize(pInitialValue) one time with the initial value (value read from an analogue floating PIC pin for example).


Call the RandGen.Rand() function to get a new random value.


The following program gives an example on how to use the pseudo-random number generator;

 

Device = 18F4620
Clock = 20
 
Include "usart.bas"
Include "convert.bas"
Include "RandGen.bas"
 
Dim RandomNumber As Byte
 
SetBaudrate(br9600)
 
// initialize the generator Initial Seed Value to 2
// for Full Random value you can use an ADC read on
// a floating AN PIC Pin
RandGen.Initialize(2)                                              
 
TRISB = 0 'All output

While true
// generates a number
RandomNumber = RandGen.Rand()  
 
// write to RS233
Write(DecToStr(RandomNumber),13,10)     
 
// visualise number on PORTB leds (on my EasyPic Board)
LATB = RandomNumber
 
DelayMS(600)
Wend

Written by Ahmed Lazreg (octal). A simple Pseudo Random Number Generator module (modulo based).

 

Link: What is a Swordfish Library?

Comments (0)
Write comment
Your Contact Details:
Comment:
[b] [i] [u] [url] [quote] [code] [img]   
Security
Please input the anti-spam code that you can read in the image.
Last Updated ( Saturday, 18 April 2009 06:42 )
 

Whos Online

  • andyo
  • Jon Chandler
  • MrDEB

Forum Activity