The Daily Click ::. Forums ::. Non-Klik Coding Help ::. Randomizer
 

Post Reply  Post Oekaki 
 

Posted By Message

monkeytherat

Hero of Time Jr

Registered
  07/11/2010
Points
  1293

VIP MemberI donated an open source project
26th November, 2010 at 01:31:30 -

Can anyone post a pseudocode or scheme code for a number randomizer?

 
If you put a million monkeys at a million keyboards, one of them will eventually write a Java program.
The rest of them will write Perl programs.

Jon Lambert

Administrator
Vaporware Master

Registered
  19/12/2004
Points
  8235

VIP MemberWii OwnerTDC Chat Super UserI am an April FoolSSBB 3265-4741-0937ACCF 3051-1173-8012360 Owner
26th November, 2010 at 02:14:06 -

MMF2 has a random number generator built in. In the expression editor, just use Random(x) where x is the number of possible values you want. For example, if you want there to be 10 numbers, use Random(10). It returns values from 0 to x-1, so for 10 it would return either 0, 1, 2, 3, 4, 5, 6, 7, 8, or 9.

 
Sandwich Time!Whoo!

JoyCheck & KeyCheck Widgets
For easy implementation of customizable joystick and keyboard controls.
http://www.create-games.com/download.asp?id=8364

monkeytherat

Hero of Time Jr

Registered
  07/11/2010
Points
  1293

VIP MemberI donated an open source project
26th November, 2010 at 02:43:47 -

Lol, I know, but this is for scheme, a lisp variant Thank you anyway

 
If you put a million monkeys at a million keyboards, one of them will eventually write a Java program.
The rest of them will write Perl programs.

Jenswa

Possibly Insane

Registered
  26/08/2002
Points
  2722
28th December, 2010 at 20:14:41 -

Just mix and mangle something yourself, because random isn't truly random.

Use the mouse coordinates, add and subtract some minutes, seconds or hours from the time and use the modulo operator to get it in between a minimum and a maximum value

 
Image jenswa.neocities.org

Hagar

Administrator
Old klik fart

Registered
  20/02/2002
Points
  1692

You've Been Circy'd!Teddy Bear
29th December, 2010 at 12:17:48 -

As Jenswa states, no PC based number generator is truely random. Given enough time the same sequence of numbers will reappear. For security applications, electrical noise is usually used to produce random bits, and these random bits are used to form random numbers.

The pseudo RNG I always use (as a hardware guy, but this could easily be done in other languages bar C examples given) is a Linear Feedback Shift Register.

http://en.wikipedia.org/wiki/Linear_feedback_shift_register

Its a bit heavy duty and is something an undergraduate electronics/software engineering student would do as an small assignment.

I recommended Jenswa's method for your needs.

 
n/a

Jenswa

Possibly Insane

Registered
  26/08/2002
Points
  2722
25th February, 2011 at 20:48:07 -

I always tend to shout: Mersenne Twister when talking about random number generators.

But I am actually using something else with a nice random number: 69069
I am multiplying by this number a starting value which I've set earlier on like the number 13 or something else. And some neat bitshifting tricks, but those are in C, not MMF although you could use multiplies and divides of course

Some number just have a better randomness property then other

 
Image jenswa.neocities.org

Assault Andy

Administrator
I make other people create vaporware

Registered
  29/07/2002
Points
  5686

Game of the Week WinnerVIP Member360 OwnerGOTM JUNE - 2009 - WINNER!GOTM FEB - 2010 - WINNER!	I donated an open source project
26th February, 2011 at 02:01:45 -

For simple super fast implementation:

http://en.wikipedia.org/wiki/Linear_congruential_generator
Image

eg.
x = (1103515245*x + 12345) mod 2^32

 
Creator of Faerie Solitaire:
http://www.create-games.com/download.asp?id=7792
Also creator of ZDay20 and Dungeon Dash.
http://www.Jigxor.com
http://twitter.com/JigxorAndy
   

Post Reply



 



Advertisement

Worth A Click