Hi,
I need to generate random bytes for x number of times and keep appending it
to a bigger byte[] array. How can I do this ?
for (int lctr=0; lctr < main.Main.NoOfa ttributes(); lctr=lctr+1){
// This line below generates the random bits for a given length
byte[] intervals = RandomFunctions .makeRandomGene Bits(length);
biggerByteArray[] = biggerByteArray + intervals ; // this is the
idea...obviousl y this statement doesn't work for byte[]
}
Any help, pointers on web are appreciated.
Many Thanks,
- Bharat. 4 59619
"Bharat Bhushan" <bh*****@talk21 .com> wrote in message
news:xl******** ********@news-binary.blueyond er.co.uk... Hi,
I need to generate random bytes for x number of times and keep appending
it to a bigger byte[] array. How can I do this ?
for (int lctr=0; lctr < main.Main.NoOfa ttributes(); lctr=lctr+1){
// This line below generates the random bits for a given length byte[] intervals = RandomFunctions .makeRandomGene Bits(length);
biggerByteArray[] = biggerByteArray + intervals ; // this is the idea...obviousl y this statement doesn't work for byte[] }
Any help, pointers on web are appreciated.
Many Thanks,
- Bharat.
byte[] intervals = ...
byte[] biggerByteArray = ...
byte[] temp = new byte[intervals.lengt h + biggerByteArray .length];
for(int i=0; i< intervals.lengt h; i++) temp[i] = intervals[i];
for(int i=0; i< biggerByteArray .length; i++) temp[i + intervals.lengt h] =
biggerByteArray[i];
biggerByteArray = temp;
...but if you are doing this lots of times it is desperately inefficient.
Much better to copy into a byte[][] and then "flatten" to byte[] once you
know the size.
(i didnt bother compiling this so it may not work).
John.
Mr. J M Court wrote: "Bharat Bhushan" <bh*****@talk21 .com> wrote in message news:xl******** ********@news-binary.blueyond er.co.uk...
Hi,
I need to generate random bytes for x number of times and keep appending it
to a bigger byte[] array. How can I do this ?
for (int lctr=0; lctr < main.Main.NoOfa ttributes(); lctr=lctr+1){
// This line below generates the random bits for a given length byte[] intervals = RandomFunctions .makeRandomGene Bits(length);
biggerByteArray[] = biggerByteArray + intervals ; // this is the idea...obviou sly this statement doesn't work for byte[] }
Any help, pointers on web are appreciated.
Many Thanks,
- Bharat.
byte[] intervals = ...
byte[] biggerByteArray = ...
byte[] temp = new byte[intervals.lengt h + biggerByteArray .length];
It would be better to use a System.arrayCop y for each of the arrays here:
System.arraycop y(intervals,0,t emp,0, intervals.lengt h);
System.arraycop y(biggerByteArr ay,0,temp,inter vals.length,
biggerByteArray .length);
biggerByteArray = temp;
The array copy does the same job as the for loops suggested, but is more
effecient.
Cheers
Rory
for(int i=0; i< intervals.lengt h; i++) temp[i] = intervals[i]; for(int i=0; i< biggerByteArray .length; i++) temp[i + intervals.lengt h] = biggerByteArray[i];
biggerByteArray = temp;
..but if you are doing this lots of times it is desperately inefficient. Much better to copy into a byte[][] and then "flatten" to byte[] once you know the size.
(i didnt bother compiling this so it may not work).
John.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Bharat Bhushan wrote: Hi,
I need to generate random bytes for x number of times and keep appending it to a bigger byte[] array. How can I do this ?
[snip]
Hi,
I don't know about efficiency (John suggested using a byte[][] and
"flattening " it at the end, which is probably fairly efficient), but
for convenience, you could just create a ByteArrayOutput Stream, then
write each byte[] into it and convert it using toByteArray() at the
end. You have to catch IOExceptions, but, AFAIK, they're pretty much
"can't happen" with ByteArrayOutput Stream.
- --
Chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)
iD8DBQE/L4H4wxczzJRavJY RAlACAJ4wppAjjt mnyRkCRlxx2Is14 uFWiACgoBui
JguxSEhknuaCjaz r4puzxEo=
=y8WP
-----END PGP SIGNATURE-----
On Tue, 5 Aug 2003 12:15:53 +0100, "Bharat Bhushan"
<bh*****@talk21 .com> wrote or quoted : I need to generate random bytes for x number of times and keep appending it to a bigger byte[] array. How can I do this ?
see http://mindprod.com/jgloss/random.html
you can generate them a byte or int or long at a time and fill in your
array.
--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: jeko |
last post by:
Hi,
is it possible to read a double variable one byte at a time.
I would want store each byte into unsigned char and then assemble again
the double variable again.
thanx
Andrea
|
by: Tim Conner |
last post by:
Which functions are available to move a part from byte into another byte
?
Let's say I have a byte of 20 and another of 40. And I want to move 5th to
15th from the first byte into occupping bytes 20 to 35 of the second
byte.
Thanks in advance,
|
by: Wasim Akram |
last post by:
Hi,
I have a field "Month" in my SQL server table. The type of this field is
"tinyint".
Now what I am doing in the code is using DataRow to read this field in a
'int' variable.
int month = (int) dataRow;
|
by: Eric |
last post by:
Is there a class that will allow me to append a byte to another? The data
that I have is binary so StringBuilder will not work.
|
by: Guoqi Zheng |
last post by:
I am really do not know so much about byte/bit, etc.
Question, if I defined a byte(), how can I add a single byte to it?
what I want is that I have an array of bytes, I loop that array, look at the
value of that individual byte, if that byte is what I want, then I insert it
into the new byte(). How can I do it?
--
Kind regards
| |
by: Narshe |
last post by:
How can I convert a byte into a byte??
You can assign a byte to a byte?, but you obviously can't do that with
an array. The way I'm currently doing it is a for loop that just copies
the data from a byte to the byte?.
There must be an easier/better way.
|
by: Seabass |
last post by:
Hello everyone,
I'm trying to do a Hex Viewer in C#. I'm reading the user selected
file byte by byte but it seems to take forever ( one minute to read a
larger file ). Is there any way to make this function work faster ?
Here is my code:
/// <summary>
/// Opens a file chooser.
|
by: efdeugenio |
last post by:
Hi, I will really appreciate if someone cans help me with this:
I have a managed c++ class that I am calling from C#. The declaration of a function in this class is:
bool CanAddTemplate(unsigned char* template, HRESULT rc, bool bInteractive)
When calling this function from c# I have:
byte template = new Byte;
bresult = CIdentificationSet.CanAddTemplate(template, rc, true);
|
by: Ashit Vora |
last post by:
Hi,
I had one small query.
I 'm coping data from an unsigned short to a char*.
code is
#include<stdio.h>
int main(void){
unsigned short type=0xFE10;
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |