Working on a little game for the BBC Microbit.
with Ada.Numerics.Discrete_Random reports "Ada.Numerics" is not a predefined library unit.
Does Ada provide another way to generate random numbers on the BBC MicroBit? arch/ARM/Nordic/svd/nrf51/nrf51_svd-rng defines a random number generator record RNG_Peripheral. Is this what I'm searching for or only used with Bluetooth?
GPS 2018 (20180528) hosted on x86_64-pc-linux-gnu
GNAT Community 2018 (20180524-73)
Active toolchain: arm-eabi
the GNAT Programming Studio
(c) 2001-2018 AdaCore
My code:
with Ada.Numerics.Discrete_Random;
package body Flip_A_Coin is
package Random_Coin is new Ada.Numerics.Discrete_Random(Coin);
G: Random_Coin.Generator;
------------------
-- Reset --
------------------
procedure Reset is
begin
Random_Coin.Reset(G);
end Reset;
------------------
-- Flip --
------------------
function Flip
return Coin is
begin
return Random_Coin.Random(G);
end Flip;
begin
Reset;
end Flip_A_Coin;
If you build using
for Runtime ("ada") use "ravenscar-full-microbit";
in your project or
--RTS=ravenscar-full-microbit
on the command line you will find the standard Ada RNGs.
You could also try, as you suggest, using the NRF51_SVD.RNG from the Ada Drivers Library, which should do the trick.
If you have floating-point numbers available, you can use U_Rand available # Mathpaqs.
There are a number of RNGs available in the PragmAda Reusable Components. Maybe one of them will suit you.
PragmARCs
Related
for the purpose of creating a syllabus, I like to know whether it is possible to insert a citation as a full citation. Right now, I have following markdown code:
# Session 1
#zhu2015.
This converts (pandoc "document.md" -o "document.pdf" --from markdown --template "eisvogel" --listings --citeproc) in the pdf as
Session 1
Zhu and Basar (2015).
Bibliography
Zhu, Quanyan, and Tamer Basar. 2015. “Game-Theoretic Methods for Robustness, Security, and Resilience of Cyberphysical Control Systems: Games-in-Games Principle for Optimal Cross-Layer Resilient Control Systems.” Control Systems, IEEE 35 (1): 46–65.
However, would it be possible to insert the reference as a full-citation in text?
Such as:
Session 1
Zhu, Quanyan, and Tamer Basar. 2015. “Game-Theoretic Methods for Robustness, Security, and Resilience of Cyberphysical Control Systems: Games-in-Games Principle for Optimal Cross-Layer Resilient Control Systems.” Control Systems, IEEE 35 (1): 46–65.
Thanks for your help!
Here's how to do this with a Lua filter: First, the filter finds the generated bibliography entry and saves it to a table, indexed by the citation key. Then it looks for the citation and replaces it with the full entry.
local refs = {}
local function store_refs (div)
local ref_id = div.identifier:match 'ref%-(.*)$'
if ref_id then
refs[ref_id] = div.content
end
end
local function replace_cite (cite)
local citation = cite.citations[1]
if citation and refs[citation.id] and #cite.citations == 1 then
return pandoc.utils.blocks_to_inlines(refs[citation.id])
end
end
return {
{Div = store_refs},
{Cite = replace_cite},
}
Save the above to a file and pass that file to pandoc with the --lua-filter command line option. The filter must run after the citeproc processer has done its work, so it should be the last command line argument. Tested with the latest pandoc version 2.12 (which no longer requires pandoc-citeproc, but it should work either way).
So im studying, and i need to run Ozcar debugger including on Mozart, i go to Oz menu and first i pick feed buffer, after that i pick Start Debugger, the compiler show me the next message:
local A B in
A = 5
B = 6
{Browse A+B}
end
% -------------------- accepted
\localSwitches
\switch +threadedqueries -verbose -expression -runwithdebugger
{Ozcar.open}
% -------------------- accepted
And then it suppose that a auxiliary windows should appears but nothing happens!!!! I need help pls!!!
Also the Oz emulator show me this:
%********************** Error: module manager *******************
%**
%** Could not link module
%**
%** Could not load functor at URL: x-oz://system/Ozcar.ozf
%**--------------------------------------------------------------
I think that the packagge of Ozcar is missing, where i can find it or how i can solve this???
You should use Mozart 1.4.0, the latest version of the 1.x Mozart branch.
Even if this question is more than 3 years old, the development of Mozart 2 is really slow and there still are a lot of features missing.
I am working on a project for the FPGA implementation of the Breakout Game. In this game, we have to break the bricks using a ball and a paddle. Some bricks may break on multiple contacts with the ball. For this, I am using an integer array to represent the number of hits required to break a particular brick. eg (2,0,1,2) represents a brickk which needs 2 hits to be broken followed by a broken brick followed by a brick which needs a single hit to be broken et al.
Also, I have done all my coding in VHDL but in order to output the results onto the VGA screen, I am using Verilog.
In VHDL, I have declared a type for an integer array in a package as follows:
package mytypes_pkg is
type int_array is array (0 to 39) of integer;
end mytypes_pkg;
then in my ball motion controlling file, I have imported work.mytypes_pkg.all and then have:
brickout:out int_array;
which contains the current state of all the bricks in the game. This array has to be passed to my Verilog file where all the VGA Display generation has to take place. There, I tried
input [39:0] bricki;
but it gives me the error
"Different types for port 'brickout' on entity and component for 'mainc'"
How can I rectify this error and do what I want to do? Is there some way of telling Verilog that bricki is also of type int_array? And do I need to import work.mytypes_pkg.all in Verilog too?
In SystemVerilog you can use typedef to define your own types, e.g.
typedef int [N-1:0] mytype;
and this way build exactly what you want. Define your types in a package and then import it:
import pkg_keccak::mytype;
...
mytype int_table;
I have been trying to display two different variables on the 7 segment led display on a spartan 3 fpga using VHDL language. This is for my final year project at uni and I'm really struggling. Can someone pleeeeeaaasssseee help? :(
Switch is a C reserved word. For VHDL you'll want to use case instead.
Here is the code for you:
if (Swtich_1 = '1') then
Seven_Seg <= Date_Time;
else
Seven_seg <= Temperature;
end if;
that is all you need :)
There are a few things you have to be careful about
Make sure you denounce the switch and it is clean
Make a simple seven segment converter to handle the data (simple case statement should do or a proces than you can find searching the net).
Hope it helps....
Summarization:
The terminology that I have been
looking for seems to be "natural
sort".
For behaviors in operating systems:
For Windows (version >= XP), Windows Explorer utilizes natural
sort.
For Linux terminals: use "ls -v" instead of plain "ls" to get natural
sort.
For programing in Delphi, use StrCmpLogicalW Windows API to get natural sort.
For programing in Delphi & Kylix & Lazarus, use hand-crafted functions to get
natural sort:
(1) Delphi wrapper for Natural Order String Comparison by Martin Pool.
http://irsoft.de/web/strnatcmp-and-natsort-for-delphi
(2) Codes of alphanum sorting algorithm in other languages from davekeolle site.
http://www.davekoelle.com/alphanum.html
(3) Other knowledgable pages:
http://www.codinghorror.com/blog/2007/12/sorting-for-humans-natural-sort-order.html
http://objectmix.com/delphi/722211-natural-sorting-optimizing-working-solution.html
http://groups.google.com/group/borland.public.delphi.language.delphi.general/browse_thread/thread/1141d49f8bbba577
http://objectmix.com/delphi/401713-alphanumeric-sort-routine-delphi.html
==========================
The following file names will be ordered in the Windows Explorer as shown below:
test_1_test.txt
test_2_test.txt
test_11_test.txt
test_12_test.txt
test_21_test.txt
test_22_test.txt
If, for example, I put them in a TStringList instance and call Sort, the sorted order is as below:
test_1_test.txt
test_11_test.txt
test_12_test.txt
test_2_test.txt
test_21_test.txt
test_22_test.txt
And for record, the above file names will be ordered in the rxvt terminal of Cygwin or xterm terminal of Linux distributions such as CentOS as shown below:
test_11_test.txt
test_12_test.txt
test_1_test.txt
test_21_test.txt
test_22_test.txt
test_2_test.txt
Could you help to comment on how to understand this difference of sorting behaviors? Furthermore, is it possible to get the same order as in Windows Explorer? Any suggestion is appreciated!
PS: My Windows locale is set to Chinese but I would think the same for English locale.
StrCmpLogicalW is able to handle numbers, the other alternative is CompareString
Thanks to Anders - the answer is StrCmpLogicalW; I have not found it's declaration in Delphi 2009 sources, so I declared it myself in the test below:
type
TMyStringList = class(TStringList)
protected
function CompareStrings(const S1, S2: string): Integer; override;
end;
function StrCmpLogicalW(P1, P2: PWideChar): Integer; stdcall; external 'Shlwapi.dll';
function TMyStringList.CompareStrings(const S1, S2: string): Integer;
begin
Result:= StrCmpLogicalW(PChar(S1), PChar(S2));
end;
procedure TForm11.Button2Click(Sender: TObject);
var
SL: TMyStringList;
begin
SL:= TMyStringList.Create;
try
SL.Add('test_1_test.txt');
SL.Add('test_11_test.txt');
SL.Add('test_12_test.txt');
SL.Add('test_2_test.txt');
SL.Add('test_21_test.txt');
SL.Add('test_22_test.txt');
SL.Sort;
Memo1.Lines:= SL;
finally
SL.Free;
end;
end;