Author Topic: Random number generator  (Read 135 times)

Pearlitic

  • Newbie
  • *
  • Posts: 23
Random number generator
« on: December 28, 2017, 11:48:54 AM »
I would like to introduce random colors to my objects in a macro. 

The early BASIC function "RND" is now "round", is the correct funtion now RAND.

Needed is random number or psuedo random number for 0-255 everytime the program loops

Best regards,


Gary,
Pearlitic

DrollTroll

  • Kindly Curmudgeon
  • Administrator
  • *****
  • Posts: 4198
Re: Random number generator
« Reply #1 on: December 31, 2017, 02:21:29 PM »
There isn't a random number generator function in BasicCAD. The best you could do for now is have a text file with a long list of random numbers, and pull from that list. It may be possible to create a subroutine to generate some sort of random number also, but I'm not sure if BasicCAD has the requisite functions to do that well.
25 years with DesignCAD

Dr PR

  • Hero Member
  • *****
  • Posts: 5499
Re: Random number generator
« Reply #2 on: December 31, 2017, 09:10:50 PM »
It has been a while but I wrote a random number generator in BASIC. It s pretty simple. Look around on the Internet for the fundamental routine. You will need a non-repeating "seed" and the normal solution is to use the date/time since it doesn't repeat.

Phil
DesignCAD user since 1987

Dempsey

  • Hero Member
  • *****
  • Posts: 1902
  • Intel i7-960, 12GB, NVidiaGTX570, Win7x64, DC26.2
    • World of van Vliet
Re: Random number generator
« Reply #3 on: January 02, 2018, 09:55:12 PM »
That was my first reaction when saw the question, but unfortunately BasicCAD has no date/time functions as far as I know.
Dempsey

Bob P

  • Hero Member
  • *****
  • Posts: 1181
    • Era Replica Automobiles
Re: Random number generator
« Reply #4 on: January 03, 2018, 03:33:08 AM »
That was my first reaction when saw the question, but unfortunately BasicCAD has no date/time functions as far as I know.

sys$(7) returns the current time. Unfortunately it is rounded off to the nearest second.

Bob P

  • Hero Member
  • *****
  • Posts: 1181
    • Era Replica Automobiles
Re: Random number generator
« Reply #5 on: January 03, 2018, 07:07:40 AM »
I see that Autohotkey has a random number generator. You might be able to call it to create a readable file.

DrollTroll

  • Kindly Curmudgeon
  • Administrator
  • *****
  • Posts: 4198
Re: Random number generator
« Reply #6 on: January 04, 2018, 12:09:37 PM »
I've programmed a few PRNGs in Delphi, and found this paper to be a helpful summary:

http://www0.cs.ucl.ac.uk/staff/d.jones/GoodPracticeRNG.pdf

Not sure how well any of these would work in BasicCAD, but it should be simple enough to create a VB, C# or Delphi app to generate a long list of random numbers from which to draw.
25 years with DesignCAD

Dr PR

  • Hero Member
  • *****
  • Posts: 5499
Re: Random number generator
« Reply #7 on: January 04, 2018, 04:35:39 PM »
DT,

Good idea. You could generate any series of numbers and then use the current time to select one - assuming that you don't need more than one "random" number per second in the same minute.

To get a pseudo-random number you could just take any AASCII text (a .TXT file from Notepad) and use it as binary numbers. For what Gery wants to do it should generate a "random" series of colors and it doesn't require a real random number generator.

The only limitation is that it will generate the same number/color sequence for the same hour/minute/second every day.

Phil
DesignCAD user since 1987

Pearlitic

  • Newbie
  • *
  • Posts: 23
Re: Random number generator
« Reply #8 on: January 08, 2018, 10:54:59 AM »
Thanks guys.  There is some really good information below.  I will see what I can do.

Best regards,

Gary