CN113138751B - Random number processing method and device and automobile - Google Patents

Random number processing method and device and automobile Download PDF

Info

Publication number
CN113138751B
CN113138751B CN202010054810.0A CN202010054810A CN113138751B CN 113138751 B CN113138751 B CN 113138751B CN 202010054810 A CN202010054810 A CN 202010054810A CN 113138751 B CN113138751 B CN 113138751B
Authority
CN
China
Prior art keywords
array
random number
random numbers
random
processing
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202010054810.0A
Other languages
Chinese (zh)
Other versions
CN113138751A (en
Inventor
张占龙
代康伟
梁海强
余军
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Electric Vehicle Co Ltd
Original Assignee
Beijing Electric Vehicle Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Electric Vehicle Co Ltd filed Critical Beijing Electric Vehicle Co Ltd
Priority to CN202010054810.0A priority Critical patent/CN113138751B/en
Publication of CN113138751A publication Critical patent/CN113138751A/en
Application granted granted Critical
Publication of CN113138751B publication Critical patent/CN113138751B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F7/00Methods or arrangements for processing data by operating upon the order or content of the data handled
    • G06F7/58Random or pseudo-random number generators
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/02Addressing or allocation; Relocation
    • G06F12/0223User address space allocation, e.g. contiguous or non contiguous base addressing
    • G06F12/023Free address space management
    • G06F12/0238Memory management in non-volatile memory, e.g. resistive RAM or ferroelectric memory
    • G06F12/0246Memory management in non-volatile memory, e.g. resistive RAM or ferroelectric memory in block erasable memory, e.g. flash memory
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F7/00Methods or arrangements for processing data by operating upon the order or content of the data handled
    • G06F7/58Random or pseudo-random number generators
    • G06F7/588Random number generators, i.e. based on natural stochastic processes
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Abstract

The invention discloses a method and a device for processing random numbers and an automobile, wherein the method comprises the following steps: determining an array for storing random numbers, wherein the array comprises N storage positions, and each storage position is used for storing one random number; wherein N is a positive integer; generating N random numbers through a random number generator, and respectively storing the N random numbers into N storage positions of the array; and acquiring random numbers from corresponding storage positions of the array. According to the scheme, the random number is read from the array immediately when the random number is needed by setting the array for storing the random number and storing a plurality of random numbers in the array in advance, so that the problem that the random number generation module needs a period of time to generate the random number after requesting the random number generation module to generate the random number in the prior art can not meet the requirement of giving the random number immediately in practical application is solved.

Description

Random number processing method and device and automobile
Technical Field
The present invention relates to the field of data processing technologies, and in particular, to a method and an apparatus for processing a random number, and an automobile.
Background
The main control chip used by the controller is generally provided with a random number generation module for generating random numbers for the safety communication function.
However, the conventional random number generation module has a disadvantage that a period of time is required for the module to generate the random number after the random number generation module is requested, and the requirement that the random number is required to be immediately given in practical application cannot be met.
Disclosure of Invention
In order to solve the technical problems, the invention provides a method and a device for processing a random number and an automobile, and solves the problems that in the prior art, after a random number generation module is requested to generate the random number, the random number generation module needs a period of time to generate the random number, and the requirement of giving the random number immediately in practical application cannot be met.
According to an aspect of the present invention, there is provided a method of processing a random number, including:
determining an array for storing random numbers, wherein the array comprises N storage positions, and each storage position is used for storing one random number; wherein N is a positive integer;
generating N random numbers through a random number generator, and respectively storing the N random numbers into N storage positions of the array;
and acquiring random numbers from corresponding storage positions of the array.
Optionally, the obtaining the random number from the corresponding storage location of the array includes:
acquiring a random number from a storage position pointed by a position pointer corresponding to the array;
when random numbers are stored in N storage positions of the array, the position pointer points to the tail end of the array;
and each time a random number in the array is acquired, resetting a storage position corresponding to the acquired random number, and pointing the position pointer to a storage position of the next unused random number.
Optionally, after obtaining the random number from the storage location pointed by the location pointer corresponding to the array, the method further includes:
acquiring the number of random numbers in the array;
if the number of the random numbers in the array is smaller than a first threshold value, generating a plurality of random numbers through a random number generation module; wherein the first threshold is less than N;
and storing the generated random numbers into the cleared storage positions in the array.
Optionally, the method further comprises:
before powering down the vehicle, the array, the number of random numbers in the array and the position pointer are stored to a non-volatile memory NVM.
Optionally, before the vehicle is powered down, after storing the array, the number of random numbers in the array, and the location pointer in the nonvolatile memory NVM, the method further includes:
and after the vehicle is powered on, acquiring the array, the number of random numbers in the array and the position pointer from the NVM.
According to another aspect of the present invention, there is provided a random number processing apparatus including:
the first processing module is used for determining an array for storing random numbers, wherein the array comprises N storage positions, each storage position is used for storing one random number, and N is a positive integer;
the second processing module is used for generating N random numbers through a random number generator and respectively storing the N random numbers into N storage positions of the array;
and the third processing module is used for acquiring the random number from the corresponding storage position of the array.
Optionally, the third processing module includes:
the first processing sub-module is used for acquiring random numbers from storage positions pointed by the position pointers corresponding to the arrays;
when random numbers are stored in N storage positions of the array, the position pointer points to the tail end of the array;
and the second processing sub-module is used for clearing a storage position corresponding to the acquired random number every time the random number in the array is acquired, and pointing the position pointer to the storage position of the next unused random number.
Optionally, the apparatus further comprises a fourth processing module;
the fourth processing module includes:
a third processing sub-module, configured to obtain the number of random numbers in the array;
a fourth processing sub-module, configured to generate a plurality of random numbers through the random number generating module if the number of random numbers in the array is smaller than a first threshold; wherein the first threshold is less than N;
and the fifth processing submodule is used for storing the generated random numbers into the cleared storage positions in the array.
Optionally, the apparatus further comprises:
and the fifth processing module is used for storing the array, the number of random numbers in the array and the position pointer to the nonvolatile memory (NVM) before the vehicle is powered down.
Optionally, the apparatus further comprises:
and the sixth processing module is used for acquiring the array, the number of random numbers in the array and the position pointer from the NVM after the vehicle is electrified.
According to a further aspect of the present invention there is provided an automobile comprising a processor, a memory, a computer program stored on the memory and executable on the processor, the processor implementing the steps of the random number processing method as described above when the computer program is executed.
The embodiment of the invention has the beneficial effects that:
in the scheme, the random number is read from the array immediately when the random number is needed by setting the array for storing the random number and storing a plurality of random numbers in the array in advance, so that the problem that the random number generation module needs a period of time to generate the random number after requesting the random number generation module to generate the random number in the prior art can not meet the requirement of giving the random number immediately in practical application is solved.
Drawings
FIG. 1 is a flow chart showing a method for processing a random number according to an embodiment of the present invention;
FIG. 2 is a second flowchart of a method for processing a random number according to an embodiment of the invention;
fig. 3 is a block diagram showing a configuration of a random number processing apparatus according to an embodiment of the present invention.
Detailed Description
Exemplary embodiments of the present invention will be described in more detail below with reference to the accompanying drawings. While exemplary embodiments of the present invention are shown in the drawings, it should be understood that the present invention may be embodied in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the invention to those skilled in the art.
As shown in fig. 1, an embodiment of the present invention provides a method for processing a random number, including:
step 11, determining an array for storing random numbers, wherein the array comprises N storage positions, and each storage position is used for storing one random number; wherein N is a positive integer;
step 12, generating N random numbers through a random number generator, and respectively storing the N random numbers into N storage positions of the array;
and step 13, acquiring random numbers from corresponding storage positions of the array.
In the embodiment, an array with n storage positions is set for storing random numbers, and the random number generation module is requested to generate a plurality of random numbers in advance to fill the array, so that when the random numbers are needed to be used, the random numbers can be obtained from the corresponding storage positions of the array immediately, and the requirement of giving the random numbers immediately in practical application is met. For example, when many controllers need to perform communication security check immediately after power-on, it is not enough to request the random number module to generate the random number, and the scheme can meet the requirement.
Preferably, step 12 includes:
when the main control chip is idle, the request generates N random numbers through a random number generator, and the N random numbers are respectively stored in N storage positions of the array. In the embodiment, the random number is generated by using the idle time of the main control chip and stored in the array, so that the random number is ensured to be generated and stored in advance under the condition that the normal use of the main control chip is not influenced.
In an alternative embodiment, step 13 includes:
acquiring a random number from a storage position pointed by a position pointer corresponding to the array;
when random numbers are stored in N storage positions of the array, the position pointer points to the tail end of the array;
and each time a random number in the array is acquired, resetting a storage position corresponding to the acquired random number, and pointing the position pointer to a storage position of the next unused random number.
In this embodiment, the storage location of the next available random number in the array is located by the location pointer, so that the random number is conveniently acquired and used. When the chip is idle, the random number module is requested to generate a random number to fill the array, the random number in the array is recorded as m, at the moment, m=n, and the position pointer p points to the tail end of the array. Assuming that only one random number is used at a time, the position pointer of the random number is recorded as p, if there is a need to use the random number at this time, one random number is taken out from the array and the corresponding position of the array is cleared to 0, where m=m-1, and the position pointer p points to the next random number position.
In an alternative embodiment, after step 13, the method further includes:
acquiring the number of random numbers in the array;
if the number of the random numbers in the array is smaller than a first threshold value, generating a plurality of random numbers through a random number generation module; wherein the first threshold is less than N;
and storing the generated random numbers into the cleared storage positions in the array.
In this embodiment, the random number generation module is initiated to generate a plurality of random numbers to fill the array by recording the random number stored in the array at any time and when the random number in the array decreases to a first threshold. It is avoided that the number of random numbers in the array has been reduced to 0, but the situation where random numbers are required occurs.
In an alternative embodiment, the method further comprises:
before powering down the vehicle, the array, the number of random numbers in the array and the position pointer are stored to a non-volatile memory NVM.
In this embodiment, the array, the random number m and the position pointer p are all stored in the NVM during power-down, so that the random number can be used immediately after the variables are taken out after the next power-up.
In an alternative embodiment, the method further comprises:
before the vehicle is powered down, after the array, the number of random numbers in the array and the position pointer are stored in the nonvolatile memory NVM, the method further comprises:
and after the vehicle is powered on, acquiring the array, the number of random numbers in the array and the position pointer from the NVM.
The embodiment can use the random number immediately after the NVM is powered on, meets the requirement that a plurality of controllers need to carry out communication security check immediately after the NVM is powered on, and avoids the condition that the random number module is not required to generate the random number.
The flow of generation and use of random numbers is described below in conjunction with fig. 2.
As shown in fig. 2, the generation and use of random numbers mainly includes the following steps:
step 21, reading the NVM data, and taking out the stored random number array, the random number m and the position pointer p;
step 22, using a random number, taking out a random number from the array and clearing the corresponding position, wherein m=m-1, p points to the next random number position;
step 23, judging whether m is reduced to limit a;
step 24, when the chip is idle, requesting to generate a random number to fill the array, wherein m is equal to the size n of the array, and p points to the end of the array;
step 25, judging whether to power down;
step 26, storing the random number arrays, m and p into the NVM;
and step 27, powering down.
In this embodiment, an array with a size of n is set for storing random numbers, and if only one random number is used each time when the random number is used, the random number module is requested to generate the random number to fill the array when the chip is idle, and the number of the random numbers in the array is recorded as m, where m=n. The position pointer for recording the random number is p, if there is a need to use the random number, one random number is taken out from the array and the corresponding position of the array is cleared to 0, at this time m=m-1, and the position pointer p points to the position of the next random number. When the random number in the array is reduced to the limit value a (a first threshold value), a request is initiated to the random number generation module to generate a plurality of random numbers to fill the array, at the moment, the number m=n of the random numbers, and the position pointer p points to the end of the array. The number of the unequal random numbers is reduced to 0 and then the random numbers are requested, so that the situation that the random numbers are not available when the random numbers are required to be used when the random number module is requested to generate the random numbers is prevented. Further, the array, the random number m and the position pointer p are all stored in the NVM during power-down, so that the random number can be used immediately after the variables are taken out after the next power-up.
Referring to fig. 3, the present invention provides a random number processing apparatus, apparatus 300 includes:
a first processing module 301, configured to determine an array for storing random numbers, where the array includes N storage locations, each of the storage locations is configured to store one random number, and N is a positive integer;
the second processing module 302 is configured to generate N random numbers through a random number generator, and store the N random numbers in N storage locations of the array respectively;
and the third processing module 303 is configured to obtain a random number from a corresponding storage location of the array.
Optionally, the third processing module 303 includes:
the first processing sub-module is used for acquiring random numbers from storage positions pointed by the position pointers corresponding to the arrays;
when random numbers are stored in N storage positions of the array, the position pointer points to the tail end of the array;
and the second processing sub-module is used for clearing a storage position corresponding to the acquired random number every time the random number in the array is acquired, and pointing the position pointer to the storage position of the next unused random number.
Optionally, the apparatus 300 further comprises a fourth processing module;
the fourth processing module includes:
a third processing sub-module, configured to obtain the number of random numbers in the array;
a fourth processing sub-module, configured to generate a plurality of random numbers through the random number generating module if the number of random numbers in the array is smaller than a first threshold; wherein the first threshold is less than N;
and the fifth processing submodule is used for storing the generated random numbers into the cleared storage positions in the array.
Optionally, the apparatus 300 further includes:
and the fifth processing module is used for storing the array, the number of random numbers in the array and the position pointer to the nonvolatile memory (NVM) before the vehicle is powered down.
Optionally, the apparatus 300 further includes:
and the sixth processing module is used for acquiring the array, the number of random numbers in the array and the position pointer from the NVM after the vehicle is electrified.
The device is a device corresponding to the method embodiment, and all implementation manners in the method embodiment are applicable to the device embodiment, so that the same technical effect as the method embodiment can be achieved.
The invention also provides an automobile, which comprises a processor, a memory and a computer program stored in the memory and capable of running on the processor, wherein the processor executes the computer program to realize the steps of the random number processing method.
While the foregoing is directed to the preferred embodiments of the present invention, it will be appreciated by those skilled in the art that various modifications and changes can be made without departing from the principles of the present invention, and such modifications and changes are intended to be within the scope of the present invention.

Claims (7)

1. A method for processing a random number, comprising:
determining an array for storing random numbers, wherein the array comprises N storage positions, and each storage position is used for storing one random number; wherein N is a positive integer;
generating N random numbers through a random number generator, and respectively storing the N random numbers into N storage positions of the array;
acquiring random numbers from corresponding storage positions of the array;
wherein obtaining the random number from the corresponding storage location of the array comprises: acquiring a random number from a storage position pointed by a position pointer corresponding to the array; when random numbers are stored in N storage positions of the array, the position pointer points to the tail end of the array;
each time a random number in the array is obtained, resetting a storage position corresponding to the obtained random number, and pointing the position pointer to a storage position of the next unused random number;
the method further comprises the steps of:
before powering down the vehicle, the array, the number of random numbers in the array and the position pointer are stored to a non-volatile memory NVM.
2. The method for processing a random number according to claim 1, further comprising, after obtaining the random number from a storage location pointed to by the location pointer corresponding to the array:
acquiring the number of random numbers in the array;
if the number of the random numbers in the array is smaller than a first threshold value, generating a plurality of random numbers through a random number generation module; wherein the first threshold is less than N;
and storing the generated random numbers into the cleared storage positions in the array.
3. The method according to claim 1, wherein after storing the array, the number of random numbers in the array, and the location pointer in the nonvolatile memory NVM before powering down the vehicle, further comprising:
and after the vehicle is powered on, acquiring the array, the number of random numbers in the array and the position pointer from the NVM.
4. A random number processing apparatus, comprising:
the first processing module is used for determining an array for storing random numbers, wherein the array comprises N storage positions, each storage position is used for storing one random number, and N is a positive integer;
the second processing module is used for generating N random numbers through a random number generator and respectively storing the N random numbers into N storage positions of the array;
the third processing module is used for acquiring random numbers from corresponding storage positions of the array;
wherein the third processing module comprises:
the first processing sub-module is used for acquiring random numbers from storage positions pointed by the position pointers corresponding to the arrays; when random numbers are stored in N storage positions of the array, the position pointer points to the tail end of the array;
the second processing submodule is used for clearing a storage position corresponding to the acquired random number every time the random number in the array is acquired, and pointing the position pointer to the storage position of the next unused random number;
further comprises: and the fifth processing module is used for storing the array, the number of random numbers in the array and the position pointer to the nonvolatile memory (NVM) before the vehicle is powered down.
5. The device for processing random numbers according to claim 4, further comprising a fourth processing module;
the fourth processing module includes:
a third processing sub-module, configured to obtain the number of random numbers in the array;
a fourth processing sub-module, configured to generate a plurality of random numbers through the random number generating module if the number of random numbers in the array is smaller than a first threshold; wherein the first threshold is less than N;
and the fifth processing submodule is used for storing the generated random numbers into the cleared storage positions in the array.
6. The apparatus for processing a random number according to claim 4, further comprising:
and the sixth processing module is used for acquiring the array, the number of random numbers in the array and the position pointer from the NVM after the vehicle is electrified.
7. An automobile comprising a processor, a memory, a computer program stored on the memory and running on the processor, the processor implementing the steps of the method for processing a random number according to any one of claims 1 to 3 when the computer program is executed by the processor.
CN202010054810.0A 2020-01-17 2020-01-17 Random number processing method and device and automobile Active CN113138751B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010054810.0A CN113138751B (en) 2020-01-17 2020-01-17 Random number processing method and device and automobile

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010054810.0A CN113138751B (en) 2020-01-17 2020-01-17 Random number processing method and device and automobile

Publications (2)

Publication Number Publication Date
CN113138751A CN113138751A (en) 2021-07-20
CN113138751B true CN113138751B (en) 2023-06-09

Family

ID=76809534

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010054810.0A Active CN113138751B (en) 2020-01-17 2020-01-17 Random number processing method and device and automobile

Country Status (1)

Country Link
CN (1) CN113138751B (en)

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JPH10177472A (en) * 1996-12-18 1998-06-30 Meteoola Syst Kk Method for generating random number string
CN107203365A (en) * 2016-03-17 2017-09-26 阿里巴巴集团控股有限公司 The generation of random number and acquisition methods and device
CN109521997A (en) * 2018-11-16 2019-03-26 中国人民解放军战略支援部队信息工程大学 The random digit generation method and device executed for shared storage multi-threaded parallel
CN109783058A (en) * 2018-12-24 2019-05-21 深圳市珍爱捷云信息技术有限公司 User identity code generating method, device, computer equipment and storage medium

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9128876B2 (en) * 2011-12-06 2015-09-08 Honeywell International Inc. Memory location specific data encryption key

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JPH10177472A (en) * 1996-12-18 1998-06-30 Meteoola Syst Kk Method for generating random number string
CN107203365A (en) * 2016-03-17 2017-09-26 阿里巴巴集团控股有限公司 The generation of random number and acquisition methods and device
CN109521997A (en) * 2018-11-16 2019-03-26 中国人民解放军战略支援部队信息工程大学 The random digit generation method and device executed for shared storage multi-threaded parallel
CN109783058A (en) * 2018-12-24 2019-05-21 深圳市珍爱捷云信息技术有限公司 User identity code generating method, device, computer equipment and storage medium

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
不重复随机数的生成算法及应用;游兰菊;;电脑知识与技术(第02期);全文 *

Also Published As

Publication number Publication date
CN113138751A (en) 2021-07-20

Similar Documents

Publication Publication Date Title
KR100837274B1 (en) Flash memory device with automatic multi-page copyback function and block replacing method thereof
US20170038969A1 (en) Data storage device and operating method thereof
US11550474B2 (en) Data storage device and method for rewriting parameters thereof
US8504897B2 (en) Memory controller
US10754552B2 (en) Data storage device and operating method thereof
US9507710B2 (en) Command execution using existing address information
US8250319B2 (en) Operating an emulated electrically erasable (EEE) memory
CN113138751B (en) Random number processing method and device and automobile
US20210191626A1 (en) Data processing system
CN113467709A (en) Memory system and operating method thereof
CN109840224B (en) Memory system and method of operating the same
KR102500618B1 (en) Memory system and operating method thereof
CN111752854A (en) Data storage device and operation method thereof
US20190258422A1 (en) Methods and apparatus for controlling flash translation layer recycle from host
US10929055B2 (en) Memory system and operating method thereof
US10776008B2 (en) Memory system and operating method thereof
CN109147847B (en) Semiconductor device and flash memory control method
US20090055574A1 (en) NAND Flash Memory Device And Related Method Thereof
US20120026795A1 (en) Electronic Apparatus and Data Reading Method
JPH05274219A (en) Storage device
KR20210048349A (en) Memory system
US20170344260A1 (en) Electronic device and operating method thereof
US11593007B2 (en) Memory system and control method thereof
US10754548B2 (en) Data storage device and method for rewriting parameters thereof
JP2005078489A (en) Microcontroller and its control method

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant