| Swordfish Library - RandGen |
|
|
| Saturday, 04 April 2009 09:37 | |
|
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
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).
|
|
| Last Updated ( Saturday, 18 April 2009 06:42 ) |
Whos Online
- andyo
- Jon Chandler
- MrDEB
Forum Activity
LCD / 18F1320 - mrdeb Saturday, 20 March 2010 06:21 - [3 replies]
A 'throw-away" PIC board - mrdeb Thursday, 18 March 2010 06:19 - [32 replies]
Credit Where Credit's Due - jon chandler Tuesday, 16 March 2010 12:01 - [9 replies]
Marching LEDs - mrdeb Saturday, 13 March 2010 22:54 - [7 replies]
USB 8 Channel Servo Controller - andyo Saturday, 13 March 2010 01:19 - [2 replies]
Dedicated Servo Controller - graham Friday, 12 March 2010 17:58 - [0 replies]
Must have....delta temperature glowies! - graham Friday, 12 March 2010 17:31 - [3 replies]



Nice. The TAP-28 boards are looking good. When I've had a buzzi...
The author (Hop) suggests to "set the target PIC's configuratio...
Graham, Thanks for fixing the spacing on the array. This is how i...
Thanks Graham, It is a problem with Flowcode because the demo wa...
Looks like you've pretty much solved every minor issue that was enc...
The low-cost servo does have one other feature. The origina...
I am not familiar with flowcode, though did you try powering the bo...
Hello there, I am still trying to get the LCD to work but I am pro...