DesignCAD 3D Max 2027 box
Now available

DesignCAD 2027

Hatches that follow their boundaries, an on-screen dial to turn your model, and a way to find any command by name, in a clean Windows 11 look.

Random number generator

Started by Pearlitic, December 28, 2017, 11:48:54 AM

Previous topic - Next topic

0 Members and 0 Guests are viewing this topic.

Pearlitic

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

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

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

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

Quote from: Dempsey 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.

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

Bob P

I see that Autohotkey has a random number generator. You might be able to call it to create a readable file.

DrollTroll

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

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

Thanks guys.  There is some really good information below.  I will see what I can do.

Best regards,

Gary

DrollTroll

See this post for a free app to generate random numbers, and a sample macro to  use them:

http://forum.designcad.com/index.php?topic=7081.msg50922#msg50922
25 years with DesignCAD